Android notification

4

I have a very simple test project that in the onCreate event of screen 1 sends a notification, which upon clicking opens screen 2.

Proposedly, I quickly click on the notification to open the new screen (testing purposes) by doing some sort of "Stress" to simulate some kind of error.

The problem is that time opens normally and sometimes a white screen remains.

Why does this occur?

I tested on 3 devices:

  • Samsung CORE 2 - DOES NOT WORK EVERY TIME.
  • Samsung Galaxy S3 mini - WORKED EVERY TIME.
  • Samsung Galaxy S duos - DEU PROBLEM A LITTLE TIME

Does this have to do with RAM, processor? Or is my code running in the wrong order?

public void sendNotification() {

    int NOTIFICATION_ID = 1;

    NotificationManagerCompat nm = NotificationManagerCompat.from(this);

    Intent it = new Intent(this, NovaTela.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(NovaTela.class);
    stackBuilder.addNextIntent(it);
    PendingIntent pit = stackBuilder.getPendingIntent(
            0, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setDefaults(Notification.DEFAULT_ALL)
                    .setAutoCancel(true)
                    .setContentIntent(pit)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("Teste Notificação")
                    .setContentText("teste");

    nm.notify(NOTIFICATION_ID, mBuilder.build());
}
    
asked by anonymous 03.07.2015 / 16:46

1 answer

3

Why it shows, time, yes, time, it's kind of complicated! Sometimes it can be the System version, among others. Please try the following:

final NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());

final Intent i = new Intent(getApplicationContext(), NovaTela.class);

i.setFlags( Intent.FLAG_ACTIVITY_SINGLE_TOP );

builder.setTicker("Ticker text. . . ");
builder.setContentTitle(" Content title text....");
builder.setContentText("Description text....");
builder .setSmallIcon(android.R.drawable.ic_input_add);
builder.setAutoCancel(true);

final PendingIntent open = PendingIntent.getActivity(this, 12345, i, PendingIntent.FLAG_UPDATE_CURRENT);

builder.setContentIntent(open);
notificationManager.notify(12345, builder.build());
    
03.07.2015 / 17:21