[SOLVED] Back from local notification -> game freez (Cocos2d-JS 3.8)

Could you please help me, I’m completely stuck:
I declare local notification on Android. Clicking the notification brings me back to game, but it freez. Event “game_on_show” is not launched. If I come back to the game by regular way - all works.

Here is how I declare local notification in AppActivity.java:

public class AppActivity extends SonarFrameworkActivity {
private static Activity sActivity;
static Context mContext;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sActivity = this;
}
public static void showLocalNotification(String tickerText, String title, String message, int interval, int tag) {
    PendingIntent sender = getPendingIntent(tickerText, title, message, tag);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, interval);
    AlarmManager am = (AlarmManager)sActivity.getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
}

private static PendingIntent getPendingIntent(String tickerText, String title, String message, int tag) {
    Intent i = new Intent(sActivity.getApplicationContext(), LocalNotificationReceiver.class);
    i.putExtra("notification_id", tag);
    i.putExtra("message", message);
    i.putExtra("title", title);
    i.putExtra("tickerText", tickerText);
    PendingIntent sender = PendingIntent.getBroadcast(sActivity,  tag, i, PendingIntent.FLAG_UPDATE_CURRENT);
    return sender;
}

}

Here is class in LocalNotificationReceiver.java

public class LocalNotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int notificationId = intent.getIntExtra(“notification_id”, 0);

    String message = intent.getStringExtra("message");
    String title = intent.getStringExtra("title");
    String tickerText = intent.getStringExtra("tickerText");

    Intent intent2 = new Intent(context, AppActivity.class);
    intent2.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT);

    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder.setContentTitle(title);
    builder.setContentText(message);
    builder.setSmallIcon(R.drawable.ic_notification);
    builder.setLargeIcon(largeIcon);
    builder.setTicker(tickerText);
    builder.setAutoCancel(true);
    builder.setDefaults(Notification.DEFAULT_ALL);
    builder.setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    manager.notify(notificationId, builder.build());
}

}

1 Like

It seems problem solved by changing:
intent2.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
to
intent2.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
in
LocalNotificationReceiver.java