Alarm does not start after reboot

I have an alarm to reset when the data connection says every 15 minutes. The problem is that after rebooting the phone, the application will be killed, and the alarm (service) will no longer start. (This is not a duplicate; other similar questions on SO do not solve my problem.)

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 <receiver
        android:name="com.sang.mobiledata.ResetBroadcastReceiver"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.sang.mobiledata.IntentAction.RECEIVE_RESETCONN_UPDATE" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>

    </receiver>

Broadcast Receiver:

public void onReceive(Context context, Intent intent) {
    // if(CONN_ACTION.equals(intent.getAction())) {
    if (intent.getAction().equalsIgnoreCase(
            "com.sang.mobiledata.IntentAction.RECEIVE_RESETCONN_UPDATE")) {
        MainActivity objMain = new MainActivity();

        objNetwork.setMobileDataEnabled(context, false);
        objNetwork.setMobileDataEnabled(context, true);

    }

    if (intent.getAction().equalsIgnoreCase(
            "android.intent.action.BOOT_COMPLETED")) {

            // code to restart/resume/retain alarm

Fire Alarm Code (onClick):

Intent myIntent = new Intent(
                    "com.sang.mobiledata.IntentAction.RECEIVE_RESETCONN_UPDATE");
            myIntent.putExtra("FLAG_KEY", false);
            PendingIntent pi = PendingIntent.getBroadcast(this, 0, myIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            AlarmManager alarmManager = (AlarmManager) this
                    .getSystemService(Context.ALARM_SERVICE);

            calendar.setTimeInMillis(System.currentTimeMillis());

            calendar.add(Calendar.SECOND, 10);
            long interval = intHrs * 3600000 + intMins * 60000;
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                    calendar.getTimeInMillis(), interval, pi);
            long mins = interval / 60000;
            Toast.makeText(
                    MainActivity.this,
                    "Data Connection will be reset every " + mins
                            + " minute(s).", Toast.LENGTH_SHORT).show();
            }

Any suggestions please?

+4
source share
1 answer

Read the document AlarmManager, it says that AlarmManagerit will not contain an alarm after a reboot.

According to the developers , Android

.... , ( , ), , .

BOOT_COMPLETED, :

... , , . , , , . RECEIVE_BOOT_COMPLETED .

, . , , , , BOOT_COMPLETED . reboot , , . . , - , BOOT_COMPLETED.

Android , .

, database, SQLite; restart reset . , . ,

. , AlarmManager . .


Android . :

, Android 3.0 , android.intent.action.BOOT_COMPLETED.

+4

All Articles