Fix crash when rotating the phone while uploading a picture

This commit is contained in:
Sylvain Berfini 2015-05-05 15:20:21 +02:00
parent e48ecd5109
commit 9bba6a3b64
3 changed files with 22 additions and 1 deletions

View file

@ -117,6 +117,7 @@
<activity android:name="org.linphone.ChatActivity"
android:theme="@style/NoTitle"
android:configChanges="orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="adjustPan|adjustResize"
android:launchMode="singleTask">
<intent-filter>

View file

@ -20,11 +20,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
/**
* @author Margaux Clerc
*/
public class ChatActivity extends FragmentActivity {
private static final String CHAT_FRAGMENT = "chatFragment";
private ChatFragment chatFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -39,6 +43,17 @@ public class ChatActivity extends FragmentActivity {
ChatFragment fragment = new ChatFragment();
fragment.setArguments(extras);
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, fragment, "ChatFragment").commit();
FragmentManager fm = getSupportFragmentManager();
chatFragment = (ChatFragment) fm.findFragmentByTag(CHAT_FRAGMENT);
// If the Fragment is non-null, then it is currently being
// retained across a configuration change.
if (chatFragment == null) {
chatFragment = new ChatFragment();
chatFragment.setArguments(extras);
fm.beginTransaction().add(R.id.fragmentContainer, chatFragment, CHAT_FRAGMENT).commit();
}
}
}

View file

@ -124,6 +124,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
super.onCreate(savedInstanceState);
instance = this;
View view = inflater.inflate(R.layout.chat, container, false);
// Retain the fragment across configuration changes
setRetainInstance(true);
//Retrieve parameter from intent
sipUri = getArguments().getString("SipUri");
@ -562,7 +565,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
@Override
protected void onPostExecute(byte[] result) {
progressDialog.dismiss();
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
mUploadingImageStream = new ByteArrayInputStream(result);