First of all, I searched a lot but I dont know what i'm doing it wrong!.
I have MainActivity which has a Listview and add button, the a button take you to addnewActivity which you can enter new items to the listview in the MainActivity and take you back to it.
Now, the problem is, every time I add new item I get new it in a new instance of the MainActivity which doesnt contain the update of the open before it! (First new item wont be visible the second time I add new item, each in different one! ).
All I need is, One MainActivity every time I add to it, so no replication (going back from it should close the app) and the data always move from the older to the newest.
- I use startActivity(intent); to more between them
- using back button from the addnewActivity should back to latest MainActivity.
I believe this is how normal app should behave!. Thanks
update:
my add new item button
private void additembutt() {
Intent intent = new Intent(this, add.class);
int idx = Items.size(); //this is the List<items> (to get the the last postion)
intent.putExtra(ID_X, idx); //newPosition
startActivity(intent);
//startActivityForResult(intent, 1); //not using this anymore, didnt work
//finish();
}
and on the add.class
Intent intent = getIntent();
idx = intent.getIntExtra(MainActivity.ID_X, -1); //take the id
Intent intentback = new Intent(add.this, MainActivity.class);
//read the user inputs and put them in msges like this as well
intentback.putExtra(ID_X, msg_idx); //Position
intentback.putExtra(ID_MESSAGE, msg_name);
startActivity(intentback);
finish();