I'm developing an app, which sends notifications in a proper time in a future. If I call AlarmManager.init () in main activity - it gives me Toast after 5 seconds on Samsung Galaxy Tab 3 and LeEco Le 2, as it should. But if I call AlarmManager.init () and kill my app (swipe it off) - I still get Toast on Samsung Galaxy Tab 3, but I dont get it on LeEco Le 2. What is my problem?
AlarmManager:
public class AlarmManager {
static android.app.AlarmManager alarmManager;
static Context context;
public static void init (Context c) {
context = c;
alarmManager = (android.app.AlarmManager) context.getSystemService(ALARM_SERVICE);
Intent intent = new Intent("com.fome.planner");
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() +
5 * 1000, alarmIntent);
}
}
Receiver:
public class MyReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Log.e("type", intent.getAction());
StringBuilder msgStr = new StringBuilder("current time: ");
Format formatter = new SimpleDateFormat("hh:mm:ss a");
msgStr.append(formatter.format(new Date()));
Toast.makeText(context, msgStr, Toast.LENGTH_SHORT).show();
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".DayActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_places_key" />
<activity android:name=".TaskCreationActivity" />
<activity android:name=".CalendarActivity" />
<activity android:name=".ListActivity" />
<receiver
android:name=".MyReceiver"
android:process=":remote"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.fome.planner"/>
</intent-filter>
</receiver>
<receiver
android:name=".MyReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
The app is probably killed when you swipe it off on your LeEco Le2 while Samsung puts your app to the background. Check the application page to see if it is still running after swipe or if it is in force stopped state.