[关闭]
@ZeroGeek 2015-08-29T09:08:06.000000Z 字数 2007 阅读 684

部分疑问整理

基础知识


1. C++ 引用与指针的区别

2. Invalidate 与 postInvaliate区别 [ok]

3. Requestlayout,onlayout,onDraw,DrawChild区别与联系[去看看View的绘制流程]

4. 两种单例模式的实现方式 [ok]

Java中int char long各占多少字节数

Android为每个应用程序分配的内存大小是多少? [gg]

C语言的宏定义sizeof的使用

RxJava,RxAndroid

横竖屏切换

  1. onSaveInstanceState-->
  2. onPause-->
  3. onStop-->
  4. onDestroy-->
  5. onCreate-->
  6. onStart-->
  7. onRestoreInstanceState-->
  8. onResume-->

如何保证后台service不被杀死?

1.重写service的onStartCommand方法。

  1.   @Override
  2.   public int onStartCommand(Intent intent, int flags, int startId) {
  3.    ...
  4.    return START_STICKY;
  5.   }

 简单介绍下这个方法,在Android开发的过程中,每次调用startService(Intent)的时候,都会调用该Service对象的onStartCommand(Intent,int,int)方法,然后在onStartCommand方法中做一些处理。然后我们注意到这个函数有一个int的返回值,这篇文章就是简单地讲讲int返回值的作用。
 

从Android官方文档中,我们知道onStartCommand有4种返回值:

2.在onDestory方法中重启Service服务.

3.修改AndroidManifest.xml

  1.   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2.   android:sharedUserId="android.uid.system">
  3.   <application android:icon="@drawable/icon"
  4.   android:label="@string/app_name"
  5.   android:allowClearUserData="false"
  6.   android:process="system" android:killAfterRestore="false">

  如果在加入了此部分代码,表示该程序运行在system进程组中,system进程组是没有权限访问sd卡的,而且service是不会自动重启的。
  

4. 提高service的优先级别.

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注