Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set restored fragment to mFragment when Activity is restored #372

Merged
merged 1 commit into from
Feb 28, 2019

Conversation

archie94
Copy link
Collaborator

Pressing back on SettingsActivity when it was restored gave this crash

java.lang.NullPointerException: Attempt to invoke virtual method 'void org.havenapp.main.SettingsFragment.save()' on a null object reference
 at org.havenapp.main.SettingsActivity.onBackPressed(SettingsActivity.java:60)
 at android.app.Activity.onKeyUp(Activity.java:2805)
 at android.view.KeyEvent.dispatch(KeyEvent.java:2701)
 at androidx.core.view.KeyEventDispatcher.activitySuperDispatchKeyEventPre28(KeyEventDispatcher.java:137)
 at androidx.core.view.KeyEventDispatcher.dispatchKeyEvent(KeyEventDispatcher.java:87)
 at androidx.core.app.ComponentActivity.dispatchKeyEvent(ComponentActivity.java:126)
 at androidx.appcompat.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:535)
 at androidx.appcompat.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
 at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent(AppCompatDelegateImpl.java:2533)
 at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:320)
 at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4384)
 at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4355)
 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3899)
 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3952)
 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3918)
 at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4045)
 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3926)
 at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4102)
 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3899)
 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3952)
 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3918)
 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3926)
 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3899)
 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3952)
 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3918)
 at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4078)
 at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4246)
 at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2397)
 at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1993)
 at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1984)
 at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2374)
 at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
 at android.os.MessageQueue.nativePollOnce(Native Method)
 at android.os.MessageQueue.next(MessageQueue.java:329)
 at android.os.Looper.loop(Looper.java:142)
 at android.app.ActivityThread.main(ActivityThread.java:6375)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

This is because we do not save the restored fragment instance in mFragment when savedInstanceState is non-null.

This PR aims to resolve that.

Signed-off-by: Arka Prava Basu <arkaprava94@gmail.com>
@lukeswitz
Copy link
Collaborator

Thank you! This made it easy to spot the next PR

@n8fr8 n8fr8 merged commit a560765 into guardianproject:master Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants