【发布时间】:2012-06-19 00:55:12
【问题描述】:
我正在使用 AlarmManager 启动每分钟运行的服务。但是,我收到“应用程序 blabla 已意外停止”。当我打开设备时,带有强制关闭按钮的警告对话框。我不知道错误是什么,因为我唯一的调试选项是使用 WIFI,并且每次重启设备时连接的 IP 都会更改。
服务在没有启动的情况下运行良好。
这是我在应用程序下运行的 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: Unable to instantiate receiver mypackage.FPBootReceiver: java.lang.ClassNotFoundException: mypackage.FPBootReceiver in loader dalvik.system.PathClassLoader
【问题讨论】:
-
你检查过 Logcat 输出了吗?
-
请阅读以上内容。我不能,因为它是一个 WIFI 调试,并且每次启动都会更改 IP 地址。有没有办法在不关闭设备的情况下发送这个 BOOT 意图?
-
如果可以调试应用程序,怎么不能得到logcat的输出?
-
正如我上面所说,我无法在启动时调试,因为每次启动时 IP 地址都会发生变化,而我唯一的调试选项是通过 WIFI。现在我设法找到一个命令行来发送 BOOT_COMPLETED 意图,我可以看到 Logcat。请参阅上面的更新。
-
在您的清单中将 mypackage.FPBootReceiver 更改为 test.aachen.FPBootReceiver。
标签: android broadcastreceiver alarmmanager boot intentservice