3D-kreativ 3D-kreativ - 4 months ago 15
Android Question

Return back to MainActivity from another activity

The

MainActivity
contains some buttons. Each button opens a new activity via an intent. These activities then have a button to return to the
MainActivity
via an intent.

But when I press a button to return to the
MainActivity
, I get some sort of menu on the screen! Someone who knows what could be wrong? Preciate some help! Thanks!

EDIT: The return button in one of the other activities:

Button btnReturn1 = (Button) findViewById(R.id.btnReturn1);
btnReturn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent returnBtn = new Intent("android.intent.action.MAIN");
startActivity(returnBtn);
}
});


The Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kullaberg.test02"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity1"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.ACTIVITY001" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.ACTIVITY002" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Activity3"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.ACTIVITY003" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>



Answer

why don't you call finish();

when you want to return to MainActivity

   btnReturn1.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        finish();
    }
});