Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AlarmManager at Boot

I am using an AlarmManager to start a service that runs every minute. However, I am getting the "The application blabla has stopped unexpectedly." warning dialog with Force Close button when I turn on the device. I do not know what the error is because the only debugging option I have is with WIFI and the IP of the connection changes every time I reboot the device.

The service runs fine without the boot.

Here is my BroadcastReceiver running under the application:

    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);
    }
}

Manifest:

    <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>

Anything wrong you see that I am doing wrong with these?

UPDATE: Managed to debug the boot and I am getting AndroidRuntime(2781): java.lang.RuntimeException: Unable to instantiate receiver mypackage.FPBootReceiver: java.lang.ClassNotFoundException: mypackage.FPBootReceiver in loader dalvik.system.PathClassLoader

like image 222
Erol Avatar asked Mar 25 '26 04:03

Erol


1 Answers

Android system can not see your Receiver, check your path unless your full package is actually "mypackage". You ether need to make it ".mypackage.FPBootReceiver" or specify the full path.

like image 115
Jug6ernaut Avatar answered Mar 27 '26 19:03

Jug6ernaut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!