I’m developing application for most major Mobile OS like iOS, Windows Phone and Android. I have a request from my client that simply possible to implement in iOS and WP but sounds really tricky in Android.
In iOS and WP, an application lifecycle is controlled through events which an object like UIApplication
and Application
receives.
In iOS, for ex., applicationDidEnterBackground:
, applicationWillEnterForeground:
, applicationWillTerminate:
and the like, clearly define application states such as Inactive, Active and Background and make the app state management logic really straight forward.
In WP, Application
receives well understanding events such as Launching, Deactivated, Activated, and Closing which make it really simple to decide what should be done in each app state logically to save as restore application wide object model.
But in Android, application state management sounds really difficult with Activities’ state changes such as onCreate
, onRestart
… onDestroy
method overriding. My problem arises where I want to control the whole application state when the user session goes expired and I want to redirect user to the sign in activity and shuts down other open activity.
Regarding the fact that calling finish()
in an activity’s onCreate()
, onRestart()
or onResume()
is ignored by Android (according to the documentation) .
Even if I override android.app.Application
and put the logic there, it sounds like controlling open activities is not possible.
I almost tried all possible combinations of activity launch mode (such as SingleTask
and SingleInstance
) though I cannot produce behavior like those exist in iOS and WP.
There is another post related to this question which may clarify my problem more.
The question exactly is, “Is it possible to produce iOS or WP application behavior in Android anyway?”