我正在使用AlarmManager启动一个每分钟运行一次的服务。然而,当我打开设备时,会弹出"应用程序blabla意外停止"的警告对话框,带有强制关闭按钮。由于唯一的调试选项是WIFI和连接的IP地址在每次重新启动设备时都会更改,因此我不知道错误是什么。
服务在没有引导的情况下可以正常运行。
这是我的BroadcastReceiver,在应用程序下运行:
服务在没有引导的情况下可以正常运行。
这是我的BroadcastReceiver,在应用程序下运行:
public class FPBootReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
android.os.Debug.waitForDebugger();
Intent bootintent = new Intent(context, FPService.class);
PendingIntent pi = PendingIntent.getService(context, 0, bootintent, PendingIntent.FLAG_UPDATE_CURRENT);
long nextUpdateTimeMillis = DateUtils.MINUTE_IN_MILLIS;
Time nextUpdateTime = new Time();
nextUpdateTime.set(nextUpdateTimeMillis);
AlarmManager FPAlarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
FPAlarm.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), nextUpdateTimeMillis, pi);
}
}
清单:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="@drawable/pc"
android:label="@string/app_name" >
<service android:name=".FPService" />
<receiver android:enabled="true" android:name="mypackage.FPBootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity
android:name=".CF_Aachen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
你看到我做错的地方了吗?
更新:成功调试启动,但是我遇到了AndroidRuntime(2781)错误:java.lang.RuntimeException: 无法实例化接收器 mypackage.FPBootReceiver: java.lang.ClassNotFoundException: mypackage.FPBootReceiver in loader dalvik.system.PathClassLoader