AlarmReceiver 没有被 android:process=":remote" 调用
AlarmReceiver not getting called with android:process=":remote"
我已经通过警报管理器为 运行 实施了一项服务。
我读了这个 link:Should I use android: process =“:remote” in my receiver?
我认为这对我的应用程序来说是个不错的功能,因为我希望该服务在我的应用程序关闭后保持 运行ning。
但是当我在清单上将这行配置添加到我的接收器时,我的服务停止被调用。
有什么线索吗?
这是我的收件人声明:
这个有效:
<receiver
android:name=".service.MyAlarmReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name=".service.MyAlarmReceiver"></action>
</intent-filter>
</receiver>
这行不通:
<receiver
android:name=".service.MyAlarmReceiver"
android:enabled="true"
android:process=":remote"
android:exported="false">
<intent-filter>
<action android:name=".service.MyAlarmReceiver"></action>
</intent-filter>
</receiver>
public class MyAlarmReceiver extends BroadcastReceiver {
public static final int REQUEST_CODE = 12345;
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Time to start scan service!");
Intent intent = new Intent(context, BeaconFinderService.class);
context.startService(intent);
}
}
这就是我启动闹钟管理器的方式:
// Construct an intent that will execute the AlarmReceiver
Intent intent = new Intent(getApplicationContext(), MyAlarmReceiver.class);
final PendingIntent pIntent = PendingIntent.getBroadcast(getApplicationContext(), MyAlarmReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.BLE_SERVICE_LOOP_TIME, pIntent);
当您在远程模式 (android:process=":remote") 下将服务配置为 运行 时,您将不得不像往常一样调试进程 :remote 。
个人bug:
所以我在尝试访问服务上的 FirebaseUser 时遇到了异常。在远程模式下,您无法访问 FirebaseUser,因为您的进程 运行s 在另一个上下文中。
初始化服务时,我必须通过 intent extras 传递给用户。
就是这样!
我已经通过警报管理器为 运行 实施了一项服务。 我读了这个 link:Should I use android: process =“:remote” in my receiver?
我认为这对我的应用程序来说是个不错的功能,因为我希望该服务在我的应用程序关闭后保持 运行ning。
但是当我在清单上将这行配置添加到我的接收器时,我的服务停止被调用。
有什么线索吗?
这是我的收件人声明:
这个有效:
<receiver
android:name=".service.MyAlarmReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name=".service.MyAlarmReceiver"></action>
</intent-filter>
</receiver>
这行不通:
<receiver
android:name=".service.MyAlarmReceiver"
android:enabled="true"
android:process=":remote"
android:exported="false">
<intent-filter>
<action android:name=".service.MyAlarmReceiver"></action>
</intent-filter>
</receiver>
public class MyAlarmReceiver extends BroadcastReceiver {
public static final int REQUEST_CODE = 12345;
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Time to start scan service!");
Intent intent = new Intent(context, BeaconFinderService.class);
context.startService(intent);
}
}
这就是我启动闹钟管理器的方式:
// Construct an intent that will execute the AlarmReceiver
Intent intent = new Intent(getApplicationContext(), MyAlarmReceiver.class);
final PendingIntent pIntent = PendingIntent.getBroadcast(getApplicationContext(), MyAlarmReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.BLE_SERVICE_LOOP_TIME, pIntent);
当您在远程模式 (android:process=":remote") 下将服务配置为 运行 时,您将不得不像往常一样调试进程 :remote 。
个人bug: 所以我在尝试访问服务上的 FirebaseUser 时遇到了异常。在远程模式下,您无法访问 FirebaseUser,因为您的进程 运行s 在另一个上下文中。 初始化服务时,我必须通过 intent extras 传递给用户。 就是这样!