Record the operation history of user clicks, use stack data structure, frequently operate the top of the stack (add, obtain, delete), use LinkedList
Capture the user's return key operation, respond to the return key, and return to the previous interface
/** * Return key processing */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode==KeyEvent.KEYCODE_BACK){ boolean result=().goBack(); if(!result){ (, "Do not exit the application", 1).show(); } return false; } return (keyCode, event); }
//Operation history stack private LinkedList<String> HISTORY=new LinkedList<String>(); /** * Processing return key * @return */ public boolean goBack() { //If it is empty, an exception will be thrown if(()>0){ if(()==1){ return false; } (); if(()>0){ String key=(); BaseView targetView=(key); (); View child=(); (child); (((), .left_to_right)); currentView=targetView; return true; } } return false; }
/** * Loading interface */ public void loadView(Class<? extends BaseView> baseViewClass) { BaseView baseView=null; //Judge whether it exists String key=(); if((key)){ baseView=(key); }else{ try { Constructor<? extends BaseView> constructor; constructor = (); baseView=(()); } catch (Exception e) { (); } (key, baseView); } (); View child=(); (child); (((), .left_to_right)); currentView=baseView; //Put into the stack (key); }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.