Rain Man Rain Man - 1 year ago 68
Android Question

Working with intent data when dealing with several activities

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">
android:value=".activities.Activity_1" />
<activity android:name=".Activity_3">
android:value=".activities.Activity_2" />


adapter I send some data to
via onclick listener (through the adapter) :

view.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

Intent intent = new Intent(v.getContext(), Activity_2.class);

and in
I retrieve that data:

private String title;
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

I dont want to use preferences to store the title, any idea how to avoid this?

Answer Source

It seems like you are fetching info from the intent during onResume which is called from Activity1 -> Activity2 and also in the way back from Activity3 -> Activity2.

You may want to consider doing so during onCreate instead. Does that make sense?

EDIT: So... I just learnt that navigation up (the "<-" on the action bar) is different from navigation back (hard button). You can solve this issue using different approaches:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download