Reputation: 23
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);
}
}
Upvotes: 0
Views: 3709
Reputation: 856
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);
Upvotes: 0
Reputation:
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.
Upvotes: 1
Reputation: 1593
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
Upvotes: 0
Reputation: 12768
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:
Upvotes: 0