0

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>

Alex Fome
  • 13
  • 5
  • If I had to guess, LeEco did something stupid and tied the app-swipe behavior to the same logic that sits behind the "Force Stop" button on your app's page in Settings. You might slightly extend your time period (e.g., to a minute) and try it again. While waiting for the alarm to go off, use `adb shell dumpsys alarm` to see if your alarm shows up. If the alarm is missing, then they are cancelling alarms (e.g., as part of Force Stop processing). If the alarm is there and goes off after 1 minute, perhaps it's a power-saving minimum alarm time. If the alarm is there and does not go off...? – CommonsWare Apr 13 '17 at 11:31
  • I've set time to 1 minute, started my app and run "adb shell dumpsys alarm". It gave my a list of alarms, but I did not found my app in it. And I did not even kill my app. And alarm has benn called (Toast showed up). – Alex Fome Apr 13 '17 at 12:44
  • Perhaps that device is even more screwed up than I thought. – CommonsWare Apr 13 '17 at 12:44
  • And when I've tried the same with Samsung - I've seen my alarm. Thank you for clearing it's all a little bit. Any futher suggestions? – Alex Fome Apr 13 '17 at 14:38
  • Take a sledgehammer to the LeEco? :-) Beyond that, I don't really know what to tell you. I have added a Le 2 to my "weird equipment to buy" list. – CommonsWare Apr 13 '17 at 14:40

1 Answers1

0

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.

Alexander M.
  • 3,308
  • 2
  • 20
  • 31
  • After I kill my app on Samsung and on LeEco they both keep logging something in Android Studio. So, if I understand you right, they both are not in force stopped state. Maybe it's something about API difference? – Alex Fome Apr 13 '17 at 12:36
  • I think it's about infamous chinese vendors trying to preserve battery. Please read Mr. CommonsWare's comment too, he dives even deeper into this problem. – Alexander M. Apr 13 '17 at 12:42