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 record 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 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 changed all my activitys 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 quite what you need, but I decided to share my experience, because when you don’t have anything. Something is very useful..
I hope I’ve helped!!
You can save in sharedPrefferences the last screen of the user, implement a method and call it always in onDestroy(); If the user closes the app.. you can create a service that forces him to stay with the app open, but I think it’s kind of "dangerous".
– Carlos Bridi
@Carlosbridi, I think calling onDestroy is not a good idea... I would record onResume, so I understood, for example if the user takes the battery, will not be able to call onDestroy for example..
– Marco Giovanni
@Carlosbridi I tried to use sharedprefferences, but when I forcibly close sharedprefferences is clean and back to default. It seems some android bug I’ve even researched about...
– Mateus Carvalho