方法一
// 申请设备电源锁,在服务start的时候。
代码:
private WakeLock mWakeLock; private void acquireWakeLock() { if (null == mWakeLock) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "LoginService"); if (null != mWakeLock) { mWakeLock.acquire(); } } } // 释放设备电源锁,在服务Destory的时候 private void releaseWakeLock() { if (null != mWakeLock) { mWakeLock.release(); mWakeLock = null; } } 方法二还有在onStartCommand里面最后return super.onStartCommand(intent, START_STICKY, startId);楼上刚刚已经说了 方法三
QQ在通知栏不是设了一个不同于一般通知的通知嘛~
代码如下:
代码:
Notification notification = new Notification(R.drawable.qqbatch_logo, getString(R.string.app_name),System.currentTimeMillis()); PendingIntent pendingintent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); notification.setLatestEventInfo(this, "xxxx", "xxxxxxxxx", pendingintent); startForeground(0x111, notification); 方法四
各种广播的监听
结束进程的方法
http://blog.csdn.net/huxueyan521/article/details/8921976
|