Displaying a progress dialog until new activity loads

I have a progress dialog I am trying to show when a user clicks a button to launch a new activity. The spinner should be displayed on the current page until the other activity appears. ( The activity can take sometimes up to 4-5 seconds to launch and without the spinner it just shows a pressed button that looks frozen )

This is what I have, it's only working if I remove hideProgressDialog();, but then the spinner will still be there when I back to the previous activity, obviously.

What am I doing wrong ?

Progress Dialog :

    public void showProgressDialog(Context context) {
    if(this.progressDialog != null) {
        this.progressDialog = null;
    this.progressDialog = ProgressDialog.show(context, "", "Chargement en cours, veuillez patienter");

public void hideProgressDialog() {
    if(this.progressDialog != null) {
        this.progressDialog = null;

Function :

public void startActivity(Context context, Class<? extends Activity> activityClass) {
    try {
            Intent intent = new Intent(this, activityClass);
    catch(Throwable e) {

Example of a button click where this calls the function to show the spinner :

public void onClick(View view) {
    if(view.getId() == R.id.changeBannerButton) {
        getBaseApplication().startActivity(this, BannerListActivity.class);


Call "hideProgressDialog();" in the onResume() method. This way, if the user presses the back button, the onResume() method gets called and immediately hides the progress dialog.

Need Your Help

How to use Fl::awake in the FLTK Library

c++ fltk

I would like to use the Fl::awake(callback) function to call functions from my main loop in an FLTK program. I am calling Fl::awake from a child thread, it returns 1 (success), but my function neve...

Window.postMessage() issue

javascript javascript-events cors postmessage

I cannot get any data if I use different domains. If I run it on the same server, no problem with it - message is obtained.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.