与应用程序关联的数据将不再继续清除。为避免这种情况,您需要将您的应用程序签名为系统应用程序。
清除数据确实会杀死该应用程序,并且一直存在。
“强制停止”经历了各种含义的反复。它曾经意味着只杀死所有进程和服务,并且清除数据也将与强制停止相同。该平台还有一些较旧的迭代,不如确定何时禁用该按钮好,这可能就是为什么您看到它在2.2中保持启用的原因。
但是在3.2版中,我相信“强制停止”的含义已更改为将应用程序置于一种状态,在该状态下,该应用程序将无法运行,直到用户做了一些明确地启动它的操作(例如从启动器启动,将其选择为输入法等)。进行更改后,“清除数据”继续终止进程并停止其服务,因此该应用程序未处于完全停止状态,因此该按钮保持启用状态。
编辑:工作代码示例:
Step 1) Create one Android BroadCastReciever and register it for two action
Manifest
<service android:name="ServiceTest" >
</service>
<receiver android:name="ReceiverCall" >
<intent-filter>
<action android:name="com.android.techtrainner" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
com.android.techtrainner is the custom action. BroadCastReceiver Class contain code to restart service again
public class ReceiverCall extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("Service Stops", "Ohhhhhhh");
context.startService(new Intent(context, ServiceTest.class));;
}
}
Step 2) Create Android service class , do some task there (I have taken one Timer to print Log) and in onDestory()
public void onDestroy() {
try {
mTimer.cancel();
timerTask.cancel();
} catch (Exception e) {
e.printStackTrace();
}
Intent intent = new Intent("com.android.techtrainner");
intent.putExtra("yourvalue", "torestore");
sendBroadcast(intent);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句