package edu.feicui.orderdishes.activity;
import java.lang.ref.WeakReference;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import edu.feicui.orderdishes.util.LogWarpper;
//Activity 的基类
public class BaseActivity extends Activity {
private final String TAG = this.getClass().getSimpleName();
protected Handler mBaseHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogWarpper.e(TAG, "onCreate");
mBaseHandler = new BaseHandler(this);
}
@Override
protected void onStart() {
super.onStart();
LogWarpper.e(TAG, "onStart");
}
@Override
protected void onResume() {
super.onResume();
LogWarpper.e(TAG, "onResume");
}
@Override
protected void onRestart() {
super.onRestart();
LogWarpper.e(TAG, "onRestart");
}
@Override
protected void onPause() {
LogWarpper.e(TAG, "onPause");
super.onPause();
}
@Override
protected void onStop() {
LogWarpper.e(TAG, "onStop");
super.onStop();
}
@Override
protected void onDestroy() {
LogWarpper.e(TAG, "onDestroy");
super.onDestroy();
}
protected void goActivity(Class<?> cls) {
Intent intent = new Intent();
intent.setClass(this, cls);
startActivity(intent);
}
static class BaseHandler extends Handler {
// 弱引用,容易被回收
WeakReference<BaseActivity> mContext;
public BaseHandler(BaseActivity activity) {
this.mContext = new WeakReference<BaseActivity>(activity);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
BaseActivity activity = this.mContext.get();
if (null != activity) {
activity.handlerMessage(msg);
}
}
}
public void handlerMessage(Message msg) {
}
}