I have several activities which are are linked together. There are : Activity_1 -> Activity_2 -> Activity_3
where activity 1 is the parent of activity 2 and activity 2 is parent of activity 3. The manifest is as follow:
<activity android:name=".Activity_1"
...>
<activity android:name=".Activity_2">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.Activity_1" />
</activity>
<activity android:name=".Activity_3">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.Activity_2" />
</activity>
in Activity_1
adapter I send some data to Activity_2
via onclick listener (through the adapter) :
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), Activity_2.class);
intent.putExtra("title",title.getText());
v.getContext().startActivity(intent);
}
});
and in Activity_2
I retrieve that data:
....
private String title;
....
@Override
protected void onCreate(Bundle savedInstanceState) {
Bundle extras = getIntent().getExtras();
if (extras != null) {
title = extras.getString("title");
}
...
// some important usage of title here
I have another onclick listener that goes from activity 2 to activity 3 and when I click on the back button, the app crashes because title is returned null
.
I dont want to use preferences to store the title, any idea how to avoid this?