0

Hey I am using VideoView as a Service. But when I make the video view full screen the toolbar is not hiding. How to hide the toolbar in service.

Thank You

Android
  • 1,410
  • 4
  • 11
  • 22
IOTA IT
  • 19
  • 3
  • `getSupportActionBar().hide();` and you need to call it in your `Activity`. Service does not have anything to do with it . – ADM Dec 28 '18 at 08:27
  • 1
    How can you use Video view in service , services don't have any UI. Post your code . – Manohar Dec 28 '18 at 08:32
  • `"I am using VideoView as a Service"` and this is the source of your problems - services do not have any UI and are not designed to have it – pskink Dec 28 '18 at 10:36

2 Answers2

1

In your activity....

public class MainActivity extends AppCompatActivity{

static MainActivity instance;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    instance=this;
}

 public static MainActivity getInstance(){return instance;}

then method for hiding Action Bar.....

public void hideActionBar()
{
   getSupportActionBar.hide();
}

}

Now, In your Service call this like given below.....

MainActivity main=MainActivity.getInstance();
main.hideActionBar 

I think it will help you but please call this at the right place in your service....

Vipul Chauhan
  • 188
  • 14
0

Following Vipul Chauhan thread (since i cant comment yet)

It is not possible to call getSupportActionBar inside service.

One of the other way you can use is by using LocalBroadcastManager

You will need to publish from your service then add broadcast receiver inside your activity that need your toolbar to be hid

Your Activity:

@Override
public void onCreate(Bundle savedInstanceState) {

  ...

  // Register to receive messages.
  // We are registering an observer (mMessageReceiver) to receive Intents
  // with actions named "custom-event-name".
  LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
      new IntentFilter("custom-event-name"));
}

// Our handler for received Intents. This will be called whenever an Intent
// with an action named "custom-event-name" is broadcasted.
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    // Get extra data included in the Intent
    String message = intent.getStringExtra("message");
    //hide your toolbar here
  }
};

@Override
protected void onDestroy() {
  // Unregister since the activity is about to be closed.
  LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
  super.onDestroy();
}

Your service will need to send the broadcast

private void sendMessage() {
  Log.d("sender", "Broadcasting message");
  Intent intent = new Intent("custom-event-name");
  // You can also include some extra data.
  intent.putExtra("message", "This is my message!");
  LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

This example is taken from here How to use LocalBroadcastManager?

More reference here: https://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager

DemiDust
  • 245
  • 2
  • 17