Search code examples
androidandroid-activityandroid-pendingintentandroid-progressbar

ProgressBar preventing to open notification (Activity)


I have an app that does HTTP requests, and I show a ProgressBar until a response arrives from the server. The ProgressBar prevents the user from clicking anywhere on the app, which is fine and expected.

The problem comes when the user has an app notification and clicks on it (which attempts to open an activity) while the ProgressBar is running. Basically, nothing happens, because the ProgressBar is blocking everything until the request finishes, and then it comes back to the activity that launched it.

Then, as the notification was created with .setAutoCancel(true), it just disappeared when the user clicked, and I don't know how to recover it or what would be the best thing to do in this cases to avoid missing it.

I thought of checking if there is a ProgressBar (isShowing) on the onCreate method of the activity opened by the notification intent, but it could be displayed on many different flows of my app, so I wonder if there is a better way than checking all of them.


Solution

  • Eventually, it turned out that it had nothing to do with the progressBar, but with the fact that I was trying to open the same activity. Using a different request code in the pending item solved the problem:

    ....
    Intent myIntent = new Intent(this, MyOtherActivity.class);
    PendingIntent contIntent = PendingIntent.getActivity(
            this, 
            (int)(System.currentTimeMillis()/1000), // This is a timestamp, so will be different each time
            myIntent, 
            0
    );