New Timer (); New TimerTask () { @Override publicvoid run () {
Intent Intent = new Intent (mainactivity.this, startactivity.class); For example this 1 seconds after automatic jump
StartActivity (Intent);
Finish ();
}
1000);//1 seconds after running the Run method automatically.
Some of them are not very good self-priming, assuming an activity that opens immediately pops up a dialog, I came up with this method indirectly implemented. (using the performclick () attribute to simulate human clicks )
public class Mainactivity extends Activity {
Button button;
intI=0; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Button=(Button) Findviewbyid (R.id.button); Button.setonclicklistener (NewView.onclicklistener () {//button click event @Override Public voidOnClick (View v) {alertdialog Alertdialog=NewAlertdialog.builder (mainactivity. This). Create (); Custom dialog here is mainly about auto-start, dialog XML is not posted out alertdialog.show (); Window Window=Alertdialog.getwindow (); Window.setcontentview (r.layout.inter_dialoglayout); FinalButton nobtn =(Button) Window.findviewbyid (r.id.inter_button_no); FinalButton yesbtn =(Button) Window.findviewbyid (R.id.inter_button_yes); Nobtn.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {Intent Intent=NewIntent (mainactivity. This, StartActivity.class); StartActivity (Intent); Finish (); } }); Yesbtn.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) { } }); Alertdialog.setcancelable (false); Set mask other control Focus}}); if(i = = 0) {Button.performclick (); Analog Click event I++; }//This dialog is only allowed to trigger once}
}
There should be a better way to welcome the exchange, I do not blame beginners.
Android---Auto-start method