Hello
I want to know how this concept is implemented in android
- Navigation in this application takes place like this::
Activity1- -- to- - -> Activity 2- -to - -.>Activity 3 - - to - -> Activity2
But on doing this ::
I pass the data from
Activity1 - - > Activity 2- -> I do not pass the data from Activity2 - - > Activity3
Now
If I navigate back to Activity2- - from - - Activity3
- The application closes because Activity2 is expecting the data which is not present in Activity3
- How can I overcome this, how can I preserve the state(even data) of activity 2 before navigating back from Activity3
Cycle has to be ::
Activity1- -- to- - -> Activity 2- -to - -.>Activity 3 - - to - -> Activity2
- How to achieve this?
- What concepts do i need to look for
I hope i am clear with my description
I have given a sample program to support my question
how to modify code to achieve this
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
Button BTN=(Button) findViewById(R.id.activity3button3);
BTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent INT=new Intent(MainActivity.this,Activity2.class);
INT.putExtra("hi", "HI");
startActivity(INT);
}
});
}
}
Activity2.java
public class Activity2 extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
Button BTN=(Button) findViewById(R.id.activity3button3);
BTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent INT=new Intent(Activity2.this,Activity3.class);
startActivity(INT);
}
});
}
}
Activity3.java
public class Activity3 extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity3);
Button BTN=(Button) findViewById(R.id.activity3button3);
BTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent INT=new Intent(Activity3.this,Activity2.class);
startActivity(INT);
}
});
}
}