Reputation: 11
I am using a an adapter function which will view the current location in the list view.
The list view is working fine, my problem is while switching to another activity and returning to the same activity my list is clear and it's starting from first what can I do for.Thanks in advance.
The below code is my Intent activity. From this only I have switched between two activities.
My adapter is
Adapter = new MyTrip_listview_Adapter(MyTrip.this, location, Date_Array, imagesview, j, context, arrayplaces);
listViewplace.setAdapter(adapter);
listViewplace.setSelection(location.size() - 1);
adapter.notifyDataSetChanged();
The below code is my Intent activity. From this only I have switch between two activity.
Here how can do the activity switching
home_lay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
}
});
trips_lay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent home_btn = new Intent(MyTrip.this, Trips_visited.class);
startActivity(home_btn);
}
});
notifi_lay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent home_btn = new Intent(MyTrip.this, Notification_from_friends.class);
startActivity (home_btn);
}
});
sett_lay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
Upvotes: 0
Views: 118
Reputation: 41
when you call another activity, u could set a flag on that intent so that it has multiple tasks.
Intent home_btn = new Intent(MyTrip.this, Trips_visited.class);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
startActivity(home_btn);
If you want to go back to the activity with listview when u exit the app. You'd have to catch the back press.
you could override onkeydown and also add moveTaskToBack(true)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
return true;
}
}
return super.onKeyDown(keyCode, event);
}
add this to your first activity.
Upvotes: 0
Reputation: 26573
I'm not sure where you put the Adapter code, it seems like you put it in onResume/onStart or something.
Just use this:
if (adapter == null) {
adapter = new MyTrip_listview_Adapter(MyTrip.this, location, Date_Array, imagesview, j, context, arrayplaces);
listViewplace.setAdapter(adapter);
listViewplace.setSelection(location.size() - 1);
} else {
adapter.notifyDataSetChanged();
}
Upvotes: 1