I have activities A and B. Activity B is started by a service while the application is closed and activity A is not on the stack. Activity A has members that B requires access to. I would also like the home button to open activity A from Activity B even if activity B is started from a service. Is there a way to inject activity A back into the stack?
Asked
Active
Viewed 900 times
3 Answers
2
In your Service start ActivityA not ActivityB and pass some parameter to ActivityA.. and in ActivityA's OnCraete method launch the ActivityB.. now you have both in the stack.
SRB Bans
- 3,096
- 1
- 10
- 21
-
-
But what if activity is A is already open, would I be adding another main activity on the stack? – the_prole Jun 22 '17 at 06:21
-
I don't know what is your application flow..But, it depends on the structure of the app, in what case you r starting the activity. BTW you can make an activity single instance. or you can check whether the activity is in the foreground of not. – SRB Bans Jun 22 '17 at 06:30
-
Yes, I made activity A single instance, and pass a bundle to it from the Service, which I can still do. I check if the bundle is not null in activity A, and if it's not I open the activity B. Problem solved. – the_prole Jun 22 '17 at 06:58
0
You can declare the logical parent of each activity in your manifest file, using the android:parentActivityName attribute (and corresponding element),for home button working.
And to add a activity back to stack Check this link for more details.
Gagan
- 745
- 10
- 31
-
I already had that attribute in my xml. I don't think it's working as your described. – the_prole Jun 22 '17 at 06:11
-
-
https://stackoverflow.com/questions/19207762/must-i-specify-the-parent-activity-name-in-the-android-manifest – the_prole Jun 22 '17 at 06:13
0
That won't be a good decision, better use the members in the B Activity and Once Activity B is launched and it's about to leave just give intent to Activity A. Also you can check if Activity A is already in the stack. If already in the stack, it will popup by itself, if not found, can pro grammatically trigger it.
Exceptional
- 2,994
- 1
- 18
- 25
-
SRB had a good idea about starting activity A from activity B but what if activity A is already on the stack? – the_prole Jun 22 '17 at 06:25
-
There is a routine to check the stack. Else you can use a flag in the Activity A's life cycle! – Exceptional Jun 22 '17 at 06:27