正在做一款锁屏应用。
做锁屏肯定用到了service,可是我发现每日手动点击自带的内存清理按钮的时候,我的那个service总是会被杀死。
而微信的后台服务却是一直正常的运行,不会被杀掉。
360的话也不会被杀死,但是360会重新启动。而且360的是两个后台服务,我猜有可能会相互作用的,杀死一个的时候另一个接收到广播把其重启。
尝试过用startForeground以及提高service优先级的方式,发现都不行,service都会被杀死。
反编译了一下微信的代码。
请大家帮忙想想办法吧。谢了
下面是微信的注册service:
<service
android:name="com.tencent.mm.booter.CoreService"
android:process=":push"
>
</service>
代码如下:
public class CoreService extends Service
implements com.tencent.mm.jni.platformcomm.f, af, bl
{
private ao bZl;
private ac bZm = new ac();
private boolean bZn = true;
public final int bZo = -1213;
private final ai bZp = new e(this);
private com.tencent.mm.modelstat.l bZq = null;
private AddrBookObserver bZr;
private WatchDogPushReceiver bZs;
private WakerLock bZt = null;
private m bZu = new m();
private ay bZv = new ay(new g(this), false);
private void oj()
{
aa.w("MicroMsg.CoreService", "[COMPLETE EXIT]");
bk.Fg().d(3, 10000, "");
bg.onDestroy();
try
{
MMReceivers.AlarmReceiver.D(getApplicationContext());
MMReceivers.AlarmReceiver.B(getApplicationContext());
Alarm.H(getApplicationContext());
label43: aa.appenderClose();
Process.killProcess(Process.myPid());
return;
}
catch (Exception localException)
{
break label43;
}
}
public final void H(boolean paramBoolean)
{
if (!paramBoolean)
{
aa.w("MicroMsg.CoreService", "[NETWORK LOST]");
bk.Fc().cFB = false;
bk.Fd().eJ(0);
bk.Fb().a(10502, "", null);
this.bZn = false;
return;
}
aa.w("MicroMsg.CoreService", "[NETWORK CONNECTED]");
bk.Fc().cFB = true;
boolean bool = this.bZm.oM();
if ((this.bZn) && (!bool))
{
Object[] arrayOfObject = new Object[1];
arrayOfObject[0] = Boolean.valueOf(this.bZn);
aa.d("MicroMsg.CoreService", "network not change or can't get network info, lastStatus connect:%b", arrayOfObject);
return;
}
if (bool)
bk.Ff().EN();
this.bZn = true;
bk.Fd().eJ(1);
bk.Fb().a(10501, "", null);
if (this.bZt == null)
this.bZt = new WakerLock(getApplicationContext());
if (!this.bZt.isLocking())
this.bZt.lock(14000L);
aa.i("MicroMsg.CoreService", "checking ready, start in 7000ms");
this.bZv.bO(7000L);
}
public final boolean a(int paramInt, byte[] paramArrayOfByte)
{
if (getSharedPreferences("system_config_prefs", com.tencent.mm.compatible.g.l.qi()).getBoolean("settings_fully_exit", true))
{
aa.i("MicroMsg.CoreService", "fully exited, no need to notify worker");
return false;
}
Intent localIntent = new Intent(this, NotifyReceiver.class);
localIntent.putExtra("notify_option_type", 2);
localIntent.putExtra("notify_uin", this.bZl.ES().sd());
localIntent.putExtra("notify_respType", paramInt);
localIntent.putExtra("notify_respBuf", paramArrayOfByte);
localIntent.putExtra("notfiy_recv_time", cj.FD());
localIntent.putExtra("notify_skey", this.bZl.ES().uo());
aa.i("MicroMsg.CoreService", "notify broadcast:" + localIntent.getAction() + ", type=" + paramInt);