Java tutorial
/** * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.chat.activity; import android.app.NotificationManager; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v4.app.FragmentActivity; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import com.chat.Utils.ToastUtil; import com.umeng.analytics.MobclickAgent; public abstract class BaseActivity extends FragmentActivity implements OnClickListener { protected NotificationManager notificationManager; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setOnCreate(); } private void setOnCreate() { // TODO Auto-generated method stub setView(); setDate(); init(); setOperation(); } /** */ protected abstract void setView(); /** ? */ protected abstract void setDate(); /** */ protected abstract void init(); /** ? */ protected abstract void setOperation(); @Override protected void onResume() { super.onResume(); // umeng MobclickAgent.onResume(this); } @Override protected void onStart() { super.onStart(); // umeng MobclickAgent.onPause(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub } // ???? private static boolean isExit = false; Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); isExit = false; } }; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exit(); return false; } return super.onKeyDown(keyCode, event); } /** * BACKonKeyDown?BACKexit * exitisExitfalse?true???20002??? * Handler?false * ???2?BACK?exitisExittrue */ public void exit() { if (!isExit) { isExit = true; ToastUtil.showToast(getApplicationContext(), "??"); // handler???? mHandler.sendEmptyMessageDelayed(0, 2000); } else { finish(); System.exit(0); } } }