首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

卸载程序跟监听卸载事件

2012-09-02 
卸载程序和监听卸载事件package com.TestUIimport java.util.Listimport android.app.Activityimport a

卸载程序和监听卸载事件

package com.TestUI;import java.util.List;import android.app.Activity;import android.net.Uri;import android.os.Bundle;import android.text.format.Time;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.widget.Toast;import android.view.View.OnClickListener;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.graphics.LightingColorFilter;import android.graphics.PorterDuff;import android.graphics.PorterDuff.Mode;public class TestUI extends Activity implements OnClickListener{    /** Called when the activity is first created. */      private Button button;       public mDeleteReceiver mDelete;        public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);                setContentView(R.layout.main);        text = (TextView) findViewById(R.id.textview);        button=(Button)findViewById(R.id.button);                      button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent delete = new Intent(Intent.ACTION_DELETE,Uri.parse("package:com.et.TextScroll"));startActivity(delete);}});           }public class mDeleteReceiver extends BroadcastReceiver{@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stubToast.makeText(context, "卸载", Toast.LENGTH_LONG).show();Log.i("11111", "22222222222");}}@Overrideprotected void onResume() {// TODO Auto-generated method stubIntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_DATA_CLEARED);filter.addAction(Intent.ACTION_PACKAGE_REMOVED);filter.addDataScheme("package");mDelete = new mDeleteReceiver();registerReceiver(mDelete, filter);super.onResume();}/***不能在onPause()注销这个广播,因为跳转到卸载画面时这个activity是pause状态**/@Overrideprotected void onPause() {// TODO Auto-generated method stub//unregisterReceiver(mDelete);super.onPause();}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubunregisterReceiver(mDelete);super.onDestroy();}}

热点排行