在我的应用程序的后退按钮问题 [英] Problem with back button in my app
本文介绍了在我的应用程序的后退按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要清除共享preference值时,我的手机被关掉?
I want to clear shared preference values when my mobile is switched off?
推荐答案
你怎么能清楚共享preference
时,该设备是开机关闭
。
How can you clear SharedPreference
when the device is switched off
.
您可以清除它在设备启动时通 BraodcastReceiver
。
You can clear it when the device starts thru BraodcastReceiver
.
public class PhoneStateReceiver extends BroadcastReceiver{
@Override
public void onReceive(final Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
//Clear your `SharedPreference` here.
}
}
}
在你的清单中补充一点:
In your manifest add this:
<receiver android:name=".receiver.PhoneStateReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
添加权限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
这篇关于在我的应用程序的后退按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文