其实这里利用了一个小技巧啦~就是通过application类中的registerActivityLifecycleCallbacks,去存储了当前正在运行的activity来实现的。(本质还是依赖于activity,但是更加灵活)
首先,在自己的application类的oncreate方法中加入
public class BSApp extends Application {
@Override
public void onCreate() {
super.onCreate();
...
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityStopped(Activity arg0) {
// TODO Auto-generated method stub
}
@Override
public void onActivityStarted(Activity arg0) {
// TODO Auto-generated method stub
}
@Override
public void onActivitySaveInstanceState(Activ