http://blog.csdn.net/wangliang198901/article/details/12342845

http://stackoverflow.com/questions/3856767/android-keeping-a-background-service-alive-preventing-process-death

http://www.cnblogs.com/cc-Cheng/p/3146143.html

调用

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.source_activity);
startService(new Intent(this, RunService.class));
}

定义

public class RunService extends Service {

@Override
public void onCreate() {
sendNotification();
}

private void sendNotification() {
Log.i("ss","____________________________sendNotification");
Notification notification = new Notification();
Intent notificationIntent = new Intent(this, ScreenRecorderActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, "3DHome", "Welcome to 3DHome !", pendingIntent);
try {
startForeground(12314, notification);
} catch (Exception e) {

}
}
@Override
public void onDestroy() {
stopForeground(true);
}

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}

更多相关文章

  1. 自定义VIEWGROUP的一个用法
  2. Android 自定义 LinearLayout
  3. Android 自定义Animation,使用Camera对View组件作三维变换
  4. android 自定义view 不执行 ondraw的解决办法
  5. Android 定义全局 ToastUtils
  6. Android通过PopupMenu定义弹出菜单的位置
  7. Android TV自定义通用标题栏(组合控件)
  8. 自定义对话框
  9. Android 自定义设置文本字体间间距

随机推荐

  1. 为什么jQuery的电子邮件验证regex如此简
  2. 只对css类进行动画处理,没有显式样式
  3. 关于jquery点击之后,标签的hover失效这个
  4. jquery 图片放大效果
  5. 在jQuery Mobile中做$(document).ready的正
  6. jQuery使用微调器加载整个HTML页面
  7. 通过调用返回参数的本地函数来构建Ajax D
  8. Zepto自定义选择器与Jq存在差异
  9. EasyUI动态展示用户信息
  10. js 中输入验证