Activity not returning when pressing back

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Activity not returning when pressing back

Postby fubz » Thu Jan 14, 2010 3:39 am

Hello,
I have my main activity A, and using a menu button I launch activity B using
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Intent intent = new Intent();
  3.  
  4. intent.setClass(ActivityA.this, ActivityB.class);
  5.  
  6. startActivity(intent);
  7.  
  8.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Now when I'm done in Activity B i want to press BACK and go back to Activity A, however, it brings me back to the home screen

How do I get Activity B to return back to Activity A??

Thanks
fubz
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 12:51 am

Top

Postby jwei512 » Thu Jan 14, 2010 9:58 am

Do you call finish() when you start ActivityB? If you don't call finish() then ActivityA will remain after ActivityB finishes.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby fubz » Thu Jan 14, 2010 3:28 pm

Nope, if I call finish() in either Activity A or Activity B then both activities close
fubz
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 12:51 am

Postby MrSnowflake » Thu Jan 14, 2010 6:02 pm

Could you show your code because this should work. Or you might have a setting wrong in AndroidManifest.xml for either one of the activities or the whole Application.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby fubz » Thu Jan 14, 2010 7:34 pm

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      android:versionCode="1"
  7.  
  8.      package="us.fubz.example" android:versionName="0.3.0">
  9.  
  10.     <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:debuggable="true">
  11.  
  12.         <activity android:name=".ActivityA"
  13.  
  14.                  android:label="@string/app_name" android:screenOrientation="portrait" android:alwaysRetainTaskState="true" android:launchMode="standard">
  15.  
  16.             <intent-filter>
  17.  
  18.                 <action android:name="android.intent.action.MAIN" />
  19.  
  20.                 <category android:name="android.intent.category.LAUNCHER" />
  21.  
  22.             </intent-filter>
  23.  
  24.         </activity>
  25.  
  26.  
  27.  
  28.    
  29.  
  30. <activity android:name="ActivityB" android:screenOrientation="portrait" android:launchMode="standard"></activity>
  31.  
  32. <activity android:name="ActivityC" android:screenOrientation="portrait" android:launchMode="standard"></activity>
  33.  
  34. </application>
  35.  
  36.     <uses-sdk android:minSdkVersion="4" />
  37.  
  38.  
  39.  
  40.  
  41.  
  42. <uses-permission android:name="android.permission.VIBRATE"></uses-permission>
  43.  
  44. <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
  45.  
  46. <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  47.  
  48.  
  49.  
  50. </manifest>
  51.  
  52.  
Parsed in 0.005 seconds, using GeSHi 1.0.8.4


There is my AndroidManifest.xml
What snippits of code would you need from my classes? ActivityA is pretty big, and ActivityB is just an Activity that contains a WebView
fubz
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 12:51 am

Re: Activity not returning when pressing back

Postby icobasco » Fri Jan 15, 2010 9:25 am

it should be usefull to know the code called before and after this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Intent intent = new Intent();
  3.  
  4. intent.setClass(ActivityA.this, ActivityB.class);
  5.  
  6. startActivity(intent);
  7.  
  8.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
User avatar
icobasco
Senior Developer
Senior Developer
 
Posts: 108
Joined: Thu Jun 04, 2009 11:12 am
Location: Italy

Top

Postby fubz » Fri Jan 15, 2010 3:43 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  public boolean onOptionsItemSelected(MenuItem item) {
  3.  
  4.                 switch (item.getItemId()) {
  5.  
  6.                           case MENU_HIGHSCORE:
  7.  
  8.                           Intent intent = new Intent();
  9.  
  10.                           intent.setClass(this, HighScore.class);
  11.  
  12.                           //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  13.  
  14.                           startActivity(intent);
  15.  
  16.  
  17.  
  18.                           mView.getThread().pause();
  19.  
  20.                           return true;
  21.  
  22.                 }
  23.  
  24.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


I'm not sure what code is run after that though
fubz
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 12:51 am

Postby Johan Degraeve » Fri Jan 15, 2010 3:48 pm

why "mView.getThread().pause(); " ?

the Activity will be paused by android itself, no need to call explicitly pause() ? I don't know if this is the reason.
regards,

Johan
Johan Degraeve
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Tue Oct 27, 2009 1:50 pm
Location: Belgium

Postby fubz » Fri Jan 15, 2010 6:31 pm

Johan Degraeve wrote:why "mView.getThread().pause(); " ?

the Activity will be paused by android itself, no need to call explicitly pause() ? I don't know if this is the reason.


I removed the mView.getThread().pause() but it doesn't change the behavior of the program at all.
fubz
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 10, 2010 12:51 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests