Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Started activity from home key screen

I have a background Service which starts an activity,

Intent i = new Intent(this, MyActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

After destroying this Activity and restart it over the "long press home key menu", this Activity starts again. But I want to start the main activity instead. How could I realise this?

like image 854
Stefan Avatar asked Feb 18 '26 13:02

Stefan


1 Answers

Could you explain in more detail? If I understand your problem try setting the FLAG_ACTIVITY_NO_HISTORY.

Alternatively a manual solution would be to check the FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY on the intent in MyActivity and launch to the main activity if you see this flag set. The following code should do that:

if ((getIntent().getFlags() & FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) > 0) {
   activity.startActivity(new Intent(context , MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));    
}
like image 98
Nic Strong Avatar answered Feb 20 '26 01:02

Nic Strong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!