Android Activity Stack Management: Bringing a Specific Activity Instance to the Top

I have a text messaging application that has two main activities:

  • TextChatActivity- conversation. May have multiple instances for multiple chains.
  • ConvListActivity - a list of all activities.

In addition, a TextChatActivityspecific conversation can be opened via the status bar notification.

What I want to do is bring a specific instance TextChatActivityto the fore.

  • Let's say I have 2 open dialogs ( TextChatActivity) A and B, and B in front.
  • Now I have received a notification that leads to conversation A. I want him to bring conversation A TextChatActivityto the front.

How can I do this without opening a new instance TextChatActivityfor conversation A?

Thank!

0
source share
2 answers

Actually, you cannot. If you have multiple instances of activity on the stack, there is no way to address a unique instance of an action so that you can bring it to the forefront.

Your architecture is not very good. Due to how Android works, you would be better off if you had one instance of this action and let the user switch between chains, rather than creating a new instance of the action, but simply disabling the underlying data for the existing activity. This way, you have only one instance of activity, and you can simply change the displayed data.

"" , , "", , . , TextChatActivity, launchMode="singleTop" FLAG_ACTIVITY_SINGLE_TOP . onNewIntent(), " " , .

"" , `onBackPressed() "" , , BACK, "" , .

+1

FLAG_ACTIVITY_CLEAR_TOP

0

Source: https://habr.com/ru/post/1652186/


All Articles