我已經實現了一個有一些步驟的公式。每一步都在新的Fragment
中使用FrameLayout
。來自相機的Android丟失片段視圖
在最後一步(FRAGMENT A
)有一個Button
。點擊此Button
時,會啓動新的Fragment
(FRAGMENT B
)和相機Intent
。
有時照片拍攝後,相機被駁回後,該FRAGMENT A
顯示,而不是FRAGMENT B
。發生這種情況時,UI
元素將被凍結,任何字段都可以固定,並且繼續使用該應用程序的唯一方法是關閉Form
並再次啓動該過程。
我以爲這是一個OOM
錯誤,所以Activity
被殺死/恢復,最後一個狀態沒有正確存儲。
我試着檢查,但方法onRestoreInstanceState()
未被調用。無論是否顯示,相機關閉後,也會調用FRAGMENT B
中的方法。這就是我所謂的打開FRAGMENT B
代碼和相機:
鹼基的片段
private void setCurrentFragment(int pos, boolean animate) {
showFragment(buildFragment(mCurrentPage), animate, animationFromRight);
....
}
private Fragment buildFragment(int pos) {
switch (mHasFamilyManager ? pos : pos + 1) {
............
case 3:
mCurrentFragment = PhotoVerificationFragment.newInstance();
if (mState.getAttachments().isEmpty()) {
switch (mState.getPictureSelector()) {
.....
case CAMERA:
onAddCameraPictureClicked();
break;
}
.....
return mCurrentFragment;
}
private void showFragment(final Fragment fragment, boolean animate,
final boolean animationFromRight) {
if (fragment != null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if (animate) {
if (animationFromRight) {
transaction.setCustomAnimations(R.anim.activity_slide_in_right,
R.anim.activity_slide_out_left);
} else {
transaction.setCustomAnimations(R.anim.activity_slide_in_left,
R.anim.activity_slide_out_right);
}
}
transaction.addToBackStack(null);
transaction.replace(R.id.container, fragment);
transaction.commit();
}
}
MainActivity
public void onAddCameraPictureClicked() {
startActivityForResult(takePictureIntent, requestCode);
.....
}
是否有人有一個想法?提前致謝!
太棒了!它的作品像一個魅力,非常感謝:) – IrApp
很高興它幫助你;) – Ale