Li Tian Gong
Li Tian Gong

Reputation: 393

Android: how to pop up a modal activity from an background activity, which remains in background

when a notification comes in, the main activity is at the background(not showing)

I want it to pop up a modal/dialog activity, but the main activity always shows as the background of the modal ...

basically what I did is using

onReceiveNotificatioin(){
          Intent mIntent = new Intent(context, PopupActivity.class);
          mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          mIntent.putExtra("msg", alert);
          startActivity(mIntent);
}

how to prevent the main activity from showing itself as well?

Upvotes: 0

Views: 1297

Answers (2)

Li Tian Gong
Li Tian Gong

Reputation: 393

I finally used "singleInstance" launchmode, since the pop up need be in its own task and no other activity will be stacked onto it, I think this is fine.

I have no idea why "singletask" and Intent.FLAG_ACTIVITY_NEW_TASK doesn't work, main activity is always shown in background

Upvotes: 0

user2550149
user2550149

Reputation:

You can always remove your previous activities from the stack by setting flag FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK. For Example:

onReceiveNotificatioin(){
          Intent mIntent = new Intent(context, PopupActivity.class);
          mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
          mIntent.putExtra("msg", alert);
          startActivity(mIntent);
}

Upvotes: 5

Related Questions