Mick
Mick

Reputation: 7947

Listeners and switching activities within an application

I have a multi-activity application. Say I set up a listener for some type of event in activity A, but then switch to a different activity B (within the same app) before the event has triggered the listener. What is the status of that listener? Does it always get destroyed? Or does it depend on the type of event? Or does it depend on whether the listener was set up within the main UI thread of activity A? Or some other conditions?

EDIT: The reason I ask is that I wish to interrogate the purchase states of a variety of in-app purchase items right at the start of my app's splash screen. This involves instigating some code and setting up a listener for "ok_here_is_the_answer()".. the problem is I'm worried that it may take longer to get the answer than the duration of the splash-screen activity. In that case do I have to start all over again in my application's second activity?

Upvotes: 2

Views: 117

Answers (2)

iTech
iTech

Reputation: 18450

If your listener is created within Activity A and is tight to its context, then it would be destroyed when the activity pause i.e. go to the background.

If you want to do operation that should survive across activities, you can define it within the application context or in a dedicated service.

Upvotes: 1

Warpzit
Warpzit

Reputation: 28162

This might not be the answer to your question but you shouldn't use a splash activity (or even a splash) for many good reasons. I'd recommend you to use a full screen dialog instead which also would solve your problem.

But about your question it depend on what kind of listener we are talking about? Anything involving the context is over and done. Handlers, threads etc. is still running though (afaik).

Upvotes: 0

Related Questions