I had to do something like this once ...
I created a class that inherits from application
and created, within it these methods to read and write the current activity.
public class AppApplication extends Application
{
private Activity mCurrentActivity = null;
public Activity getCurrentActivity(){
return mCurrentActivity;
}
public void setCurrentActivity(Activity mCurrentActivity){
this.mCurrentActivity = mCurrentActivity;
}
}
I also created a class that contained the base implementation of the activity's
public class BaseActivity extends Activity{
protected AppApplication application;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
//faz o cast para o tipo da minha classe de Application
application = (AppApplication)this.getApplicationContext();
}
@Override
protected void onResume() {
super.onResume();
//cada vez que é criada ou é resumida a activity grava a activity atual
//ou seja sempre vou ter a Activity atual "gravada"
//você pode fazer guardar ao invés da instância da activity, grava uma TAG que identifica e grava em algum local, e na hora de abrir o app você ler deste local.
application.setCurrentActivity(this);
}
}
I've changed all my activity to
public class Exemplo extends BaseActivity {
...
}
and in the manifest add your AppApplication class
<application
android:name=".Globais.AppAplication"
android:icon=...
android:label=...
android:theme=...>
<activity...
I know it's not very well what you need, but I decided to share my experience, because when you do not have anything .. something is very useful ..
I hope I have helped !!