One of the classes I've written needs to react when the following Activity
events occur:
- onStart()
- onPause()
- onResume()
- onStop()
I can react to those on the Activity itself:
public class Activity extends ApplicationContext
{
protected void onCreate(Bundle savedInstanceState);
protected void onStart();
protected void onRestart();
protected void onResume();
protected void onPause();
protected void onStop();
protected void onDestroy();
}
From the Activity
I could tell the object in question that a certain event has occurred, but I don't like this idea: it requires the developer to implement the logic outside my object/class
. Ideally I would like the object to be responsible for registering these events and set itself as a listener, independent of the Activity
.
Any ideas? Thanks in advance.
Application.ActivityLifecycleCallbacks
, may be useful to someone: gist.github.com/alexjlockwood/6298122 – Overtask