add progress bar when one activity loads other activity

Go To StackoverFlow.com

2

This is my activity oncreate() method. I set a positive button ok with a dialogue window. when I click on it, it navigates UI activity staticDisplay.class. I want to set a progress bar after clicking ok in the dialogue window until it loads the next activity.

public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "ACTIVITY ONCREATE");
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.dialog);
    setContentView(R.layout.main);

    if (Registration.isRunning == false) {

        TextView title = new TextView(this);
        title.setText("DM2");
        title.setBackgroundColor(Color.DKGRAY);
        title.setPadding(10, 10, 10, 10);
        title.setGravity(Gravity.CENTER);
        title.setTextColor(Color.WHITE);
        title.setTextSize(20);
        /* alert message */
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCustomTitle(title);

        builder.setMessage(R.string.app_description).setPositiveButton(
                "Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        if (Registration.isRunning == false) {

                            startService(new Intent(
                                    getApplicationContext(),
                                    Registration.class));
                        }
                        staticInfo();
                        if (Registration.ruid == null)
                            Registration.ruid = uId;

                        startActivity(new Intent(getApplicationContext(),
                                StatisticDisplay.class));
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    } else {
        startActivity(new Intent(getApplicationContext(),
                StatisticDisplay.class));
    }
}

StaticDisplay.class on create method

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.statdisplay);


    usage_btn = (Button) findViewById(R.id.appstat);
    usage_btn.setOnClickListener(this);
    setting_btn = (Button) findViewById(R.id.setting);
    setting_btn.setOnClickListener(this);
}
2012-04-04 03:48
by thej
Take a look at this solution, it should help you.

http://stackoverflow.com/questions/6150617/how-to-start-and-finish-progressbar-dynamically-in-android/6151210#615121 - Sartaj 2012-04-04 03:54

if you accept more answer, people will be more willing to help you - Win Myo Htet 2012-04-04 04:02


2

you can use AysncTask for background process to be done and showing progressdialog as follows,

call the class

        new Task().execute(CurrentActivity.this);  

In Task Class:

        private class Task extends AsyncTask<Void, Void, Void> 
             { 
                 ProgressDialog dialog;
                 Context context;
                public Task(Context context)
                { 
                  this.context=context;
                   //constructor for this class
                }
               protected void onPreExecute() {            
                 //create the progress dialog as 
                   dialog=new ProgressDialog(context);
              } 
             protected Void doInBackground(Void... JSONArray) { 

           //Place your background process code     

            }

            protected void onPostExecute(Void unused) {
                 //dismiss the progressdialog 
                dialog.dismiss();
           } 
       }
2012-04-04 04:32
by deepa
shouldn't calling the class be like this : new Task(CurrentActivity.this).execute(); - MHSFisher 2017-12-13 06:21


2

This Code , Working For me

private ProgressDialog progress;
Button CallButton;

@Override
    protected void onCreate(Bundle savedInstanceState) 
    {
     progress = new ProgressDialog(Page.this);
     CallButton=(Button)findViewById(R.id.button1);

      CallButton.setOnClickListener(this);

   }

@Override
    public void onClick(View v)
    {
        switch (v.getId()) {
        case R.id.button1:
             progress.setMessage("Please Wait Loading...");
       progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
       progress.setIndeterminate(true);
    progress.show();
     new Thread() 
     {

         public void run() 
         {

             Intent i = new Intent(Page.this,Update.class);
             startActivity(i);
             progress.dismiss();
         }

     }.start();


            break;
}
}
2015-04-07 11:14
by Mano


0

Please look at to following code snippet,

progDailog = ProgressDialog.show(loginAct,"Process ", "please wait....",true,true);

new Thread ( new Runnable()
{
     public void run()
     {
      // your loading code goes here
     }
}).start();

 Handler progressHandler = new Handler() 
 {

     public void handleMessage(Message msg1) 
     {

         progDailog.dismiss();
         }
 }

In the run() method, you can put your loading code.

2012-04-04 04:16
by Lucifer
Ads