Weetu
Weetu

Reputation: 1773

Return to calling activity if running, otherwise start a new one?

I have an activity which performs OAuth authorization, token renewal etc.

I call it from several places. When it completes, it usually launches my "default" activity (a list of items owned by the user), but in some cases (e.g. when editing an item) I'd like for it to return to the calling activity instead.

So, I'd like to check if the calling activity is running. If it is, I'd like to return to the calling activity. Otherwise I'd like to launch a new one (which I can already do).

TL;DR: How can I check if the calling activity is still running?

Upvotes: 0

Views: 43

Answers (1)

Olexander Myznikov
Olexander Myznikov

Reputation: 295

You can use your own implementation of ActivityLifecycleCallbacks to manage all activities. Just create your implementation of interface:

public class CustomApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        registerActivityLifecycleCallbacks(new CustomActivityLifecycleCallback());
    }
}

Upvotes: 2

Related Questions