我有一个Android应用程序,我计划在将来使用警报管理器执行事件(位置更新).只要应用程序在前台或后台运行,预定事件就会按预期执行.但是一旦我强制关闭任务管理器下的应用程序,或者当应用程序处于后台时由于内存问题导致android系统杀死应用程序时,我不再能够从警报管理器接收广播.
正如各种帖子和博客所建议我尝试使用1)Intent.Flag_Include_Stopped_Packages 2)接收器android:process =":remote"in manifest 3)接收器android:exported ="true"in manifest
在服务中:
Intent locationIntent = new Intent("com.dummy.intent");
locationIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
locationIntent.putExtra(LocationLibraryConstants.LOCATION_BROADCAST_EXTRA_LOCATIONINFO, locationInfo);
context.sendBroadcast(locationIntent, "android.permission.ACCESS_FINE_LOCATION");
Run Code Online (Sandbox Code Playgroud)
在清单中:
<receiver android:name=".NearestStationBroadcastReceiver" android:enabled="true"
android:exported="true"
android:process=":remote">
<intent-filter>
<action android:name="com.dummy.intent" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?