0

I just want to show progress bar before new activity starts. When I start activity from previous activity, the new screen first shows dummy progress bar (white screen with only progressbar) and after 2 or 3 second starts the new activity.

listCategory.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
        Intent iMenuList = new Intent(thirdstep.this,  fifthscreen.class);
        startActivity(iMenuList);
    }
});

public class fifthscreen extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fifthscreen);
    }
}
Mario Kutlev
  • 4,897
  • 7
  • 44
  • 62
smart guy
  • 23
  • 2
  • 8

4 Answers4

1

You can try it using handler as below:

listCategory.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View arg1,
        int position, long arg3) {
//Display your progressBar here
Handler mHand  = new Handler();
    mHand.postDelayed(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            Intent iMenuList = new Intent(thirdstep.this,  fifthscreen.class);
            //Dismiss progressBar here
            startActivity(iMenuList);
        }
    }, 2000);   
    }
}
});

You need to put this code inside onItemClick method.

  • but i want when user click on listview on thirdscreen first show blankscreen with only progressbar after 3 or 5 second show new activity – smart guy Sep 17 '13 at 12:19
  • i want before starting new activity first show progressbar for few second then start new activity – smart guy Sep 17 '13 at 12:20
  • If you want a total blank screen then you should create a dummy activity only for showing progress bar. –  Sep 17 '13 at 12:21
  • @smartguy When you put the intent inside Handler.postDelayed as I displayed in my code, it will start with the given delay i.e. 2000 milliseconds in my example code, which is 2 seconds. After this delay it will call the new activity. Start the progress bar when user clicks the list and dismiss it when intent inside handler is called. –  Sep 17 '13 at 12:25
  • but in ur code u start progressbar on previous activity i want to when user click on new activity from previous activity nothing will show on screen except blank screen with progressbar after finish time of progressbar start new activity – smart guy Sep 17 '13 at 12:29
  • Ok, do you want to display a progress dialog with spinner or a horizontal loading progress bar? –  Sep 17 '13 at 12:32
0

Ok If your problem is that the activity takes a lot of time to display maybe you want to inflate the xml after the activity is displayed.

Here are the steps:

  1. Load a simply Activity and display it on the screen
  2. Show a progress bar
  3. Inflate a Layout containing all components you need in the activity
  4. Manage other initializations
  5. Hide the progress bar
Seraphim's
  • 12,559
  • 20
  • 88
  • 129
0

You can place an imageView with width and height as fill_parent and change its background images frequently, that will give an illusion of a incrementing progress bar.

Inflate ur layout with another layout having imageView with width and height as fill_parent and a background image of progressBar showing initial value. Then use handlers..

new Handler().postDelayed(new Runnable() {

        @Override
        public void run() 
        {
            imageView.setBackgroundResource(R.drawable.progressImage2);

        }
    }, 3200);


new Handler().postDelayed(new Runnable() {

    @Override
    public void run() 
    {

        Intent intent=new Intent(getApplicationContext(),SecondActivity.class);
        finish();
        startActivity(intent);
    }
}, 5000);
Bhavna
  • 836
  • 2
  • 6
  • 19
0
 private class log_in extends AsyncTask<String,Void,String>{
        ProgressDialog pDialog;
        int a=0;
       boolean value1;
        @Override
         protected void onPreExecute(){
            pDialog = new ProgressDialog(LoginActivity.this);
            pDialog.setMessage("Authenticating user...");
            pDialog.show();
         }
        @Override
        protected Boolean doInBackground(String... params) {
           if(a>300)
           {value1=true;}
           else{a++;
             value1=false;}
            return value1;
        }
        protected void onPostExecute(Boolean params){
            super.onPostExecute(params);
            pDialog.dismiss();
            if(params){
                Intent intent=new Intent(LoginActivity.this,menu.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                LoginActivity.this.startActivity(intent);
            }
           else{
               error.setText("Wrong password or username combination");
            }

        }

     }

just call new log_in().execute(); where you want to call your next activity

Auto-Droid ツ
  • 1,583
  • 1
  • 17
  • 31