zoukankan      html  css  js  c++  java
  • AndroidのActivity之后台隐藏


    1
    public class MainActivity extends Activity { 2 /** Called when the activity is first created. */ 3 NotificationManager nm; 4 Notification notifi; 5 PendingIntent pi; 6 @Override 7 public void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 10 notifi = new Notification(R.drawable.ic_launcher,"",System.currentTimeMillis()); 11 Intent intent = new Intent(this,MainActivity.class); 12 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK); 13 pi = PendingIntent.getActivity(this, 0, intent, 0); 14 notifi.setLatestEventInfo(this,"别当心", "哥还在", pi); 15 notifi.flags = Notification.FLAG_INSISTENT|Notification.FLAG_ONGOING_EVENT; 16 setContentView(R.layout.main); 17 18 } 19 20 @Override 21 public void onBackPressed() { 22 // TODO Auto-generated method stub 23 //super.onBackPressed(); 24 AlertDialog.Builder builder = new AlertDialog.Builder(this); 25 builder.setIcon(R.drawable.ic_launcher); 26 builder.setTitle("是否退出"); 27 //builder.setMessage(""); 28 builder.setPositiveButton("退出", new DialogInterface.OnClickListener() { 29 30 @Override 31 public void onClick(DialogInterface dialog, int which) { 32 // TODO Auto-generated method stub 33 finish(); 34 android.os.Process.killProcess(android.os.Process.myPid()); 35 } 36 }); 37 builder.setNeutralButton("隐藏", new DialogInterface.OnClickListener() { 38 39 @Override 40 public void onClick(DialogInterface dialog, int which) { 41 // TODO Auto-generated method stub 42 Intent intent = new Intent(Intent.ACTION_MAIN); 43 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 44 intent.addCategory(Intent.CATEGORY_HOME); 45 MainActivity.this.startActivity(intent); 46 47 } 48 }); 49 builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { 50 51 @Override 52 public void onClick(DialogInterface dialog, int which) { 53 // TODO Auto-generated method stub 54 55 } 56 }); 57 58 builder.create().show(); 59 } 60 61 62 63 64 @Override 65 public void finish() { 66 // TODO Auto-generated method stub 67 super.finish(); 68 nm.cancel(R.drawable.ic_launcher); 69 } 70 71 @Override 72 protected void onDestroy() { 73 // TODO Auto-generated method stub 74 super.onDestroy(); 75 Log.e("MainActivity", "onDestroy"); 76 nm.cancelAll(); 77 } 78
    79 @Override 80 protected void onStop() { 81 // TODO Auto-generated method stub 82 super.onStop(); 83 nm.notify(R.drawable.ic_launcher, notifi); 84 } 85 86 87

  • 相关阅读:
    如何从程序集中加载及卸载插件(下)
    Castle AOP 系列(四):实现一个简单的基于上下文调用的权限校验机制
    Castle AOP 系列(一):对类方法调用的拦截
    Mussel使用系列(六):分布式调用的牛刀小试
    新发现XmlNode中变态的地方
    我们发现你在XX邮箱的账号密码与其他网站被盗账号密码一致 请立即更改密码。
    html5 css3 新特性一览表
    [android] Http Post 请求
    [vs 使用技巧] VS2013显示行数 行号
    ORACLE数据库存储使用情况查询命令
  • 原文地址:https://www.cnblogs.com/bvin/p/2645584.html
Copyright © 2011-2022 走看看