I am developing an Android app. There is an Activity which showing Button.
When a button is pressed ProgressDialog should appear and behind ProgressDialog there should be another Activity that should open.
I want activity other then this Activity in which button is. How can I achieve this?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.gamemenu);
TextView tvStart = (TextView)findViewById(R.id.start);
//TextView tvSettings = (TextView)findViewById(R.id.settings);
TextView tvAbout = (TextView)findViewById(R.id.instruction);
TextView tvExit = (TextView)findViewById(R.id.exit);
tvStart.setOnClickListener(this);
//tvSettings.setOnClickListener(this);
tvAbout.setOnClickListener(this);
tvExit.setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId()){
case R.id.start:
ProgressDialog pd=new ProgressDialog(StartMenu.this);
pd=ProgressDialog.show(StartMenu.this,"Loading","Please Wait",false);
Handler handler=new Handler();
Runnable gotologin=new Runnable()
{
public void run()
{
startActivity(new Intent(StartMenu.this,AndroidGame.class));
finish();
}
};
handler.postDelayed(gotologin, 3000);
pd.dismiss();
// finish();
break;
// Intent iStart = new Intent(getApplicationContext(), AndroidGame.class );
// startActivity(iStart);
// break;
/*case R.id.settings:
Intent iSettings = new Intent(getApplicationContext(), GameSettings.class );
startActivity(iSettings);
break;*/
case R.id.instruction:
Intent inInstructions = new Intent(getApplicationContext(), Instructions.class );
startActivity(inInstructions);
break;
case R.id.exit:
((Activity)v.getContext()).finish();
//this.finish();
break;
}
}
You can show the
ProgressDialogin this way.But,I don’t think this progressDialog would been seen as the new Activity would be loaded on the screen before you can show theProgressDialog.If you want to show a
ProgressDialogon click for Some time for your requirement,you can achieve that usingHandler‘s that would load the the new Activity after some predecided time.A sample example which would hold the
ProgressDialogfor 3 Sec is as followed:Required Answer: