Android BaseActivity 主活动父类定义及实现
收集器用于收集子类 activity
package activitytest.example.com.activitytest;
import android.app.Activity;
import java.util.ArrayList;
import java.util.List;
/**
* Created by gkq on 15-7-3.
*/
public class ActivityCollector {
public static List<Activity> activities = new ArrayList<>();
public static void addActivity(Activity activity) {
activities.add(activity);
}
public static void removeActivity(Activity activity) {
activities.remove(activity);
}
public static void finishAll() {
for (Activity activity : activities){
if(!activity.isFinishing()) {
activity.finish();
}
}
}
}
父类 activity 管理收集器
package activitytest.example.com.activitytest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class BaseActivity extends Activity {
public static final String TAG = "BaseActivity";
@Override
protected void onCreate(Bundle savedInterfaceState) {
super.onCreate(savedInterfaceState);
Log.d(TAG, getClass().getSimpleName());
ActivityCollector.addActivity(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
ActivityCollector.removeActivity(this);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论