Activity back to home

Put your problem here if it does not fit any of the other categories.

Activity back to home

Postby wahid2oo9 » Wed Mar 09, 2011 7:41 am

I want to know the code to get an activity back to the first screen,
if i call finish(); in the third activity it just goes back to the previous one,...

a image would be like,
Home
page2
page3 (page im on) and i call finish(); on this page
page4

results would be
Home
page2 (im on this page now, instead Home)
page3
page4

Thanks
Wahid
wahid2oo9
Developer
Developer
 
Posts: 36
Joined: Fri Dec 31, 2010 7:07 am

Top

Re: Activity back to home

Postby raj_J2ME » Wed Mar 09, 2011 8:14 am

This link will be helping to you in this regards.
http://www.warriorpoint.com/blog/2009/05/24/android-how-to-switch-between-activities/

Please check and revert... :)
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: Activity back to home

Postby wahid2oo9 » Wed Mar 09, 2011 8:47 am

Thanks, as i posted my first post, i found a webpage with the right code i was looking for,

I have used the following, kind of simular like yours,

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home: Toast.makeText(this, "Home", Toast.LENGTH_LONG).show(); startActivity(new Intent("com.calculator.Home"));
break;


" startActivity(new Intent("com.calculator.Home"));"

thanks for ur help anyway ! :) really appreciate it.
wahid2oo9
Developer
Developer
 
Posts: 36
Joined: Fri Dec 31, 2010 7:07 am

Re: Activity back to home

Postby dist » Thu Mar 10, 2011 6:24 am

Using the code you provided will wreck havoc with your back button.

When you press back, it will follow your activity trail. So if the user is in your app for awhile, and then they start pressing back, it will jump all over your activities. It could also possibly keep activities in memory, thus creating more overhead then you are expecting. (I haven't tested this, just looking at the code and this is what I would expect it to do).

You should use the logic in the post above. It will be a much cleaner interface.
dist
Freshman
Freshman
 
Posts: 4
Joined: Mon Feb 21, 2011 9:38 pm

Re: Activity back to home

Postby wahid2oo9 » Fri Mar 11, 2011 1:24 pm

You are right! and you just cleared everything in my mind that i was confused of.
I was playing with my app testing it out, then i reliazed it was jumping from activity to some other activity :shock:
i was like hmm wats going on, and now i read ur post, now i understand why its happening.
Thanks ill follow raj_j2me post,

Thanks both of your help!
if i get stuck somewhere ill let you both know, thanks again. :)


(EDIT)
I mean like, if i have a menu that pops up when a user clicks "Menu" on his phone. and if he clicks on a button, i want it to go to the first page .
i no how to create buttons and that, but im looking for buttons on menu, and making them go to which activity you want.
wahid2oo9
Developer
Developer
 
Posts: 36
Joined: Fri Dec 31, 2010 7:07 am

Re: Activity back to home

Postby dist » Fri Apr 29, 2011 5:14 am

wahid2oo9 wrote:(EDIT)
I mean like, if i have a menu that pops up when a user clicks "Menu" on his phone. and if he clicks on a button, i want it to go to the first page .
i no how to create buttons and that, but im looking for buttons on menu, and making them go to which activity you want.


Sorry for the late reply..

You can handle this with starting your activities by using startActivityForResult, then when you return, use the following logic (ie, detect that the user wants to go back one function):

Code: Select all
   public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == VIEW_ITEM) {
         if (resultCode == GO_BACK) // go Back is a static variable
            finish();
      }


Rinse / repeat this code through all of your activites until you get back to the main menu.
dist
Freshman
Freshman
 
Posts: 4
Joined: Mon Feb 21, 2011 9:38 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 26 guests