1

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

JoCuTo
  • 2,463
  • 4
  • 28
  • 44
  • Demetria, very confusing question I think this is, need to explain somewhat easily by you. please. – Pratik Dasa Jun 09 '14 at 11:16
  • thanks pratik . English is not my natural language, sorry . Basically if one user finishes my game he goes to a screen whose name is "waiting results", the result will be sent by push notification.When the push comes In the app I check the push values If the push has a value "Win" users goes to win screen(win activity) in the same case for lost (goes to activity lost)....but sometimes the push comes late, and devices goes to sleep mode, in this case on android<4.1.x when the push comes (late) the app turn off. – JoCuTo Jun 09 '14 at 11:32
  • its ok, I think its depends on your device setting, that how much time would be awake, like 5 sec, 10 sec, 1 min when its on idle mode. But in this case you can check one condition, untill and unless push not come till then forcefully awake your screen. – Pratik Dasa Jun 09 '14 at 11:38
  • Yes I force it with PowerManager as you can see on my code and the app doesn't turn off,but with this solution I have another problem ,after the push come the screen is always On , waiting the unlock pattern so the battery will be dead fast . Example: User has android 2.3.6 ,user finishes the game, app goes to waiting result. User forgets the game and goes to take the lunch. Device goes to sleep mode. Push come, he has lost, the screen is On (always) and waiting the user pattern.(never goes to sleep mode) when the user takes the phone after 3 hours the battery is empty. Do you understand me? – JoCuTo Jun 09 '14 at 12:03
  • Then make some timer task and keep wake lock on for some minutes only, like if push would not come for 5 mins then automatically screen goes to sleep in power saving mode, you can do something like this way. – Pratik Dasa Jun 09 '14 at 12:07
  • Demetria, got my point or not???? – Pratik Dasa Jun 09 '14 at 12:25
  • Sorry is my first time on stack.. where is the points? – JoCuTo Jun 09 '14 at 12:42
  • should we share our emails?? I think its the better way to communicate as you are new here – Pratik Dasa Jun 09 '14 at 12:42
  • I think that you need to validate my question. isnt it? – JoCuTo Jun 09 '14 at 12:43

0 Answers0