Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Activity does not show on android wear

I've made a simple app that needs (yes it really does) to show an immersive warning. I've implemented this with an activity launched from a service. Most of the time it shows correctly, but sometime when the wearable is idle it doesn't. onStart() and onResume() runs but the view doesn't show on screen. Any ideas ?

(This is on an Android Gear Live from I/O)

It's triggered from a service by :

   Intent i = new Intent(MyService.this, MyActivity.class);
   i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
   i.setAction("disconnected");
   startActivity(i);

Some of the activities code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d("MyActivity", "onCreate");
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON|
                         WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
                         WindowManager.LayoutParams.FLAG_FULLSCREEN |
                         WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
                         WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    setContentView(R.layout.activity);
    disconnectedView = (TextView)findViewById(R.id.disconnectedView);
}
@Override
protected void onStart() {
    super.onStart();
    Log.d("MyActivity", "onStart");
}
@Override
protected void onResume() {
    // Corrected after comment from MikeC
    //super.onStart();
    super.onResume();
    Log.d("MyActivity", "onResume");
    if (getIntent().getAction() != null && getIntent().getAction().equals("disconnected"))
        startVibration();
}
like image 600
frma71 Avatar asked Oct 21 '22 05:10

frma71


1 Answers

Try setting the flags in onResume() instead, seems to have worked for me.

@Override
public void onResume()
{
    super.onResume();

    // Keep awake
    getWindow().addFlags( WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                          WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );
}
like image 68
Morne Avatar answered Oct 27 '22 19:10

Morne