Skip to content

Fix crash: v can not be null after view is destroyed#101

Open
limedroid wants to merge 1 commit into
masterfrom
cursor/fix-v-cannot-be-null-4d82
Open

Fix crash: v can not be null after view is destroyed#101
limedroid wants to merge 1 commit into
masterfrom
cursor/fix-v-cannot-be-null-4d82

Conversation

@limedroid

Copy link
Copy Markdown
Owner

Problem

When a user starts an async network request and leaves the screen before it completes, the presenter callback still calls getV(). After onDestroy / onDestroyView, the view has already been detached, so getV() threw:

java.lang.IllegalStateException: v can not be null

This is a common crash reported in issues #71, #77, and #82.

Solution

  1. XPresent: getV() now returns null when the view is detached instead of throwing. detachV() also checks v != null before clearing the weak reference.
  2. PBasePager: Async onNext / onFail callbacks guard view access with hasV() before updating the UI.
  3. PMulti: Same hasV() guard for consistency.

Notes

Presenter code that calls getV() should check hasV() (or null-check the return value) in async callbacks to avoid updating a destroyed view.

Open in Web Open in Cursor 

When a network request completes after Activity/Fragment destruction,
getV() threw IllegalStateException ("v can not be null"). Return null
from getV() when the view is detached, fix detachV() null-safety, and
guard async presenter callbacks with hasV() checks.

Co-authored-by: WangLei <limedroid@users.noreply.github.com>
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.

2 participants