0

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?

the_prole
  • 8,275
  • 16
  • 78
  • 163

3 Answers3

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
  • I like that idea, let me try it – the_prole Jun 22 '17 at 06:18
  • 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
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