I have a ViewFlipper that contains multiple chat windows at any given time. When I click a user A on my contact list and open a chat with that user A, the ViewFlipper is brought into the foreground and I'm able to start a chat with user A. If I want to then open another, concurrent chat with user B, I must press the back button on the android device, be brought back to the contact list and click on another user.
When this happens, as soon as I click on User B, the previous chat from User A is deleted since the onCreate() method was called in the ViewFlipper Activity.
How can I avoid this problem? I would like to click on User B and have it added to the ViewFlipper instead of the ViewFlipper resetting itself.
Do I have to put the ViewFlipper as a Service? Is there something I can do in the onPause, onResume, or maybe reprogram the onBackPressed method?
The contact screen is implemented as follows:
list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ListView android:id="@+id/android:list" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:text="@string/no_friend" android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
contact_list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/icon" android:layout_width="48dip"
android:layout_height="48dip" />
<TextView android:id="@+id/text" android:layout_gravity="center_vertical"
android:layout_width="0dip" android:layout_weight="1.0"
android:layout_height="wrap_content" />
</LinearLayout>
contact.java
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
View v =
convertView = mInflater.inflate(R.layout.contact_list,null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(friends[position].userName);
if (friends[position].status == STATUS.NEW_MSG)
holder.icon.setImageBitmap(mNewMsgIcon);
if (friends[position].status == STATUS.OPEN)
holder.icon.setImageBitmap(mOpenChat);
return convertView;
}
Where mInflater is
mInflater = LayoutInflater.from(context);
The ListAdapter is defined within contact.java (it would take up the entire screen if I put it here)
When you press the back button onDestroy() for the view flipper Activity will be called and so your previous session is deleted. Why not give the user an option to select the chat options from the view flipper Activity itself so the session will be retained and you could just flip the views...