Marian
Marian

Reputation: 144

back button go back to another activity not the one i define it in the manifest

I need to define EditProfileActivity as the parent activity to EditActivity to enable the back button in tool bar in the EditActivity but it is not working

note : the back button back to the activity that was open before the parent activity "EditProfileActivity"

    <activity
        android:name=".controllers.drawer.AgendaActivity"
        android:label="@string/title_activity_agenda"
        android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity
        android:name=".controllers.EditProfileActivity"
        android:label="@string/title_activity_edit_profile"></activity>

    <activity
        android:name=".controllers.EditActivity"
        android:label="@string/title_activity_edit"
        android:parentActivityName=".controllers.EditProfileActivity">

        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".controllers.EditProfileActivity" />

    </activity>

i call editActivity from EditProfileActivity:

 public void onClick(View view) {


    Intent intent = new Intent(EditProfileActivity.this, EditActivity.class);


    switch (view.getId()) {
        case R.id.edit_name:

            intent.putExtra("toolBarTitle", "Enter your name");
            intent.putExtra("editText", tvName.getText().toString());
            break;

        default:
            throw new RuntimeException("Unknow button ID");
    }

    startActivityForResult(intent, 1);
    finish();
}

Upvotes: 2

Views: 53

Answers (1)

atifali
atifali

Reputation: 193

Use this code

public void onClick(View view) {


    Intent intent = new Intent(EditProfileActivity.this, EditActivity.class);


    switch (view.getId()) {
        case R.id.edit_name:

            intent.putExtra("toolBarTitle", "Enter your name");
            intent.putExtra("editText", tvName.getText().toString());
            break;

        default:
            throw new RuntimeException("Unknow button ID");
    }

    startActivityForResult(intent, 1);
}

Upvotes: 2

Related Questions