I´m doing a game on Android. I´m using gcm push notifications and basically what I´m doing with the push is check their content in order to know if push has a winner or loser value , if has a win value and the user is on the screen "waiting result" app goes to other activity screen (waiting or loser screen depending on the push value). So the schema is:
If user is on waiting screen and push comes goes to push screen value.
All work perfectly on android 4.2.x but on 4.1.x and earliest (the last version I support is 2.3.6) doesnt work when the push comes and the devices is on sleep mode, on this case ( api<16 , push comes and device is in sleep mode) the app turn off ,not errors only turn off, and I need to start it again. In order to solve this trouble I have written the following lines and force tha app to be working, and works well ,but the problem now is that the screen is turn on always, never goes to sleep mode and ,as you can imagine, the battery will be dead fast in the case the your are not playing in that monent. The schema for my problem with the new implementation is:
When android version<4.1.x and screen is on sleep mode. Push comes and screen is On (always) waiting user screen unlock.
My questions is: Do you have any ideas about why the app turns off on api<16? Do you have another implementation idea?
This function inside GcmIntentService extends IntentService class runs in the case that push notification has a win value
if(win){
DataStore.userRefereeWin=true;
if (currentUserSituation().contains("Waiting") && (android.os.Build.VERSION.SDK_INT < 16)){
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
wakeLock.acquire();
}
sound = Uri.parse("android.resource://" + getPackageName() + "/" + whatWinSound());
Intent recentAppIntent = new Intent(GcmIntentService.this, Win.class);
recentAppIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
contentIntent = PendingIntent.getActivity(getBaseContext(), 1, recentAppIntent, 0);
}
Thanks in avenced