android怎么让程序不被杀死,【转】android让普普通通app不被其他程序kill

【转】android让普通app不被其他程序kill

转自:google搜索 android startForeground

如http://blog.csdn.net/yyingwei/article/details/8509402

运行一个service

@Override

public void onDestroy() {

// Make sure our notification is gone.

stopForegroundCompat(R.string.system_message_title);

super.onDestroy();

}

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

Builder builder = new Notification.Builder(this);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, DeskSetting.class), 0);

builder.setContentIntent(pendingIntent)

.setSmallIcon(R.drawable.ic_launcher)// 设置状态栏里面的图标(小图标)

// .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.i5))//下拉下拉列表里面的图标(大图标)

// .setTicker("this is bitch!") //设置状态栏的显示的信息

.setOngoing(false)

.setOnlyAlertOnce(true)

.setShowWhen(false)

.setOnlyAlertOnce(true)

.setPriority(Notification.PRIORITY_MIN)

.setWhen(System.currentTimeMillis())// 设置时间发生时间

.setAutoCancel(true)// 设置可以清除

.setContentTitle(getText(R.string.fetion_launcher_started))// 设置下拉列表里的标题

.setContentText(getText(R.string.about_desk));// 设置上下文内容

Notification notification = builder.getNotification();

notification.flags = Notification.FLAG_ONGOING_EVENT;

notification.flags |= Notification.FLAG_NO_CLEAR;

notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;

Log.d(TAG, "notification.flags " + notification.flags);

startForeground(3030, notification);

// startForegroundCompat(1166, notification);

mNM.cancel(3030);

return super.onStartCommand(intent, flags, startId);

}

PS:system应用的话,直接在AndroidManifest中的application标签加入android:persistent="true"就好

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值