开发者

Issue in single instance of an activity in Android

开发者 https://www.devze.com 2023-01-15 16:48 出处:网络
I have two activities. A and B. A starts B. Both are running in the screen and both are visible. Say now B is visible.

I have two activities. A and B. A starts B. Both are running in the screen and both are visible. Say now B is visible.

On a special key press, I want to bring the A to the front and make it active. The problem I am facing is when the special key is pressed, another instance of A is launched and the new instance is brought to the front.

But I want the original A to come to the front. I want to make this change in the framework layer rather than application specific by using the singleInstance theme in the launch开发者_JAVA百科Mode in AndroidManifest file.


From Google's Android-documentation:

Defining launch modes

Launch modes allow you to define how a new instance of an activity is associated with the current task. You can define different launch modes in two ways: Using the manifest file

When you declare an activity in your manifest file, you can specify how the activity should associate with tasks when it starts. Using Intent flags

When you call startActivity(), you can include a flag in the Intent that declares how (or whether) the new activity should associate with the current task.

So you can start your Activity A from Activity B using an Intent and passing the FLAG_ACTIVITY_SINGLE_TOP flag.


Why don't you want to use the manfiest to achieve that?

If changes in the manifest were possible from the code the application would be able to change it's permissions after installation which doesn't make sense.

0

精彩评论

暂无评论...
验证码 换一张
取 消