java - Same activity getting stacked -


i have activity suppose finish , close application. now, in cases, varying on how user navigating activity, activity getting stacked. when activity stacking up, calling finish() or android.os.process.killprocess(android.os.process.mypid()); or both showing same activity again.

the manifest:

<activity             android:name="newactivities.homeactivity"             android:label="@string/title_activity_home"             android:screenorientation="portrait">         </activity> 

the activity:

public class homeactivity extends activity {      private edittext studentnameedittext;     private button startyourstorybutton, loginbutton, navcollegesbutton, settingsbutton, search_friends_button, browsestoriesbutton;     private textview textview1;       @override     protected void oncreate(bundle savedinstancestate){         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_home); //      if (getfrompreference("loginstatus").equalsignorecase("true")) { //          finish(); //          saveinpreference("loginstatus", ""); //      }         // set action bar         actionbar bar = getactionbar();         bar.setbackgrounddrawable(new colordrawable(color.parsecolor("#009945")));         bar.settitle("study story");         bar.seticon(r.drawable.statusbar_icon);         int titleid = getresources().getidentifier("action_bar_title", "id", "android");         textview yourtextview = (textview) findviewbyid(titleid);         yourtextview.settextcolor(getresources().getcolor(r.color.white_colour));         yourtextview.settypeface(typefacecontroller.titleface(homeactivity.this));            // studentnameedittext = (edittext)         // findviewbyid(r.id.studentnameedittext);         startyourstorybutton = (button) findviewbyid(r.id.startyourstorybutton);         // loginbutton = (button) findviewbyid(r.id.loginbutton);         navcollegesbutton = (button) findviewbyid(r.id.navcollegesbutton);         // settingsbutton = (button) findviewbyid(r.id.settingsbutton);         // search_friends_button = (button)         // findviewbyid(r.id.search_friends_button);         browsestoriesbutton = (button) findviewbyid(r.id.browsestoriesbutton);         // textview1 = (textview) findviewbyid(r.id.textview1);          // set font type         // studentnameedittext.settypeface(typefacecontroller.generaltextface(homeactivity.this));         startyourstorybutton.settypeface(typefacecontroller.titleface(homeactivity.this));         // loginbutton.settypeface(typefacecontroller.titleface(homeactivity.this));         navcollegesbutton.settypeface(typefacecontroller.titleface(homeactivity.this));         // settingsbutton.settypeface(typefacecontroller.titleface(homeactivity.this));         // search_friends_button.settypeface(typefacecontroller.titleface(homeactivity.this));         browsestoriesbutton.settypeface(typefacecontroller.titleface(homeactivity.this));         // textview1.settypeface(typefacecontroller.titleface(homeactivity.this));          startyourstorybutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view arg0){                 intent = new intent(homeactivity.this, signup.class);                 i.putextra("signupcaller", "home");                 startactivity(i);             }         });          // loginbutton.setonclicklistener(new view.onclicklistener() {         //         // @override         // public void onclick(view arg0){         // intent = new intent(homeactivity.this, login.class);         // startactivity(i);         // }         // });          // search_friends_button.setonclicklistener(new view.onclicklistener() {         //         // @override         // public void onclick(view v){         // intent = new intent(homeactivity.this,         // findstudentbrowsestoryactivity.class);         // i.putextra("button", "search_friends_button");         // i.putextra("searchstring", studentnameedittext.gettext().tostring());         // startactivity(i);         //         // }         // });          browsestoriesbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v){                 intent = new intent(homeactivity.this, findstudentbrowsestoryactivity.class);                 i.putextra("button", "browsestoriesbutton");                 startactivity(i);              }         });          navcollegesbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v){                 intent = new intent(homeactivity.this, collegelistactivity.class);                 startactivity(i);              }         });          // settingsbutton.setonclicklistener(new view.onclicklistener() {         //         // @override         // public void onclick(view v){         // intent = new intent(homeactivity.this, homesettingsactivity.class);         // i.putextra("fromactivity", "homesettingsactivity");         // startactivity(i);         // finish();         //         // }         // });      }  //  @override //  protected void onstart(){ //      if (getfrompreference("loginstatus").equalsignorecase("true")) { //          finish(); //      } //      super.onstart(); //  } // //  @override //  protected void onresume(){ //      if (getfrompreference("loginstatus").equalsignorecase("true")) { //          finish(); //      } //      super.onresume(); //  }      // =========login button action bar     @override     public boolean oncreateoptionsmenu(menu menu){         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.home_menu, menu);         return true;     }      // =========login button action bar     @override     public boolean onoptionsitemselected(menuitem item){         // handle item selection         switch (item.getitemid()) {         case r.id.home_login_string:             intent = new intent(homeactivity.this, login.class);             // finish();             startactivity(i);             return true;         default:             return super.onoptionsitemselected(item);         }     }      // logic fix logout      @override     public void onbackpressed(){ //      intent startmain = new intent(intent.action_main); //      startmain.addcategory(intent.category_home); //      startmain.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_task);; //      startactivity(startmain); // //       int pid = android.os.process.mypid(); // //       android.os.process.killprocess(pid); // return; }         android.os.process.killprocess(android.os.process.mypid());         finish();     }      // method save variable in preference     public void saveinpreference(string name, string content){         sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this);         sharedpreferences.editor editor = preferences.edit();         editor.putstring(name, content);         editor.commit();     }      // getting content preferences     public string getfrompreference(string variable_name){         string preference_return;         sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this);         preference_return = preferences.getstring(variable_name, "");          return preference_return;     } } 

please tell me going wrong? why activity stacking?

p.s: cannot use single top etc causes transition issues existing custom theme!

take 1 application class extends application , take 1 arraylist , maintain references of activities in arraylist.

when click on button in desired activity finish activities using arraylist.

take 1 base activity. super class of activities

public class baseactviity extends activity { @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     app application = (app) getapplication();     application.addactivity(this);   } }  take 1 application class   public class app extends application { public app() {     if (listactivty == null) {         listactivty = new arraylist<baseactviity>();   } }  public arraylist<baseactviity> listactivty;  public void addactivity(baseactviity actviity) {     if (!listactivty.contains(actviity)) {         listactivty.add(actviity);     }   }  }   take 4 samples activity classes ......  1) public class firstactivity extends baseactviity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.first); }  public void send(view view) {     intent intent = new intent(this, secondactivity.class);     startactivity(intent);  } } 2) public class secondactivity extends baseactviity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.first);  }  public void send(view view) {     intent intent = new intent(this, thirdactivity.class);     startactivity(intent);  } }  3).........................  4) ............................  in 4 th activity class placed following code  in desire activity means final activity,override onbackpressed   public void onbackpressed() {      super.onbackpressed();     app application = (app) getapplication();     arraylist<baseactviity> listactivty = application.listactivty;     (baseactviity actviity : listactivty) {         actviity.finish();       } } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -