Ways to bring an Android app in background to foreground

后端 未结 2 1402
遇见更好的自我
遇见更好的自我 2020-12-05 20:55

Here is the scenario:

AndroidManifest.xml defines a single Activity with android:launchMode=\"singleTask\". (This means there should be a single activit

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 21:14

    In MyMainActivity definition (AndroidManifest.xml):

    
     
     
    
    

    Programmatically bringing application to foreground:

    Intent it = new Intent("intent.my.action");
    it.setComponent(new ComponentName(context.getPackageName(), MyMainActivity.class.getName()));
    it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.getApplicationContext().startActivity(it);
    

    Note: context.startActivity(it) would NOT work when the context object is same as the activity one wants to bring up.

提交回复
热议问题