BaseFragment: avoid using requireContext() in permission result callback
java.lang.IllegalStateException: at androidx.fragment.app.Fragment.requireContext (Fragment.java:17) at com.wireguard.android.fragment.BaseFragment$setTunnelStateWithPermissionsResult$1.invokeSuspend (BaseFragment.java:4) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (BaseContinuationImpl.java:2) at kotlinx.coroutines.UndispatchedCoroutine.afterResume (UndispatchedCoroutine.java:19) at kotlinx.coroutines.AbstractCoroutine.resumeWith (AbstractCoroutine.java:13) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (BaseContinuationImpl.java:2) at kotlinx.coroutines.UndispatchedCoroutine.afterResume (UndispatchedCoroutine.java:19) at kotlinx.coroutines.AbstractCoroutine.resumeWith (AbstractCoroutine.java:13) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (BaseContinuationImpl.java:2) at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.java:2) at android.os.Handler.handleCallback (Handler.java:790) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loop (Looper.java:164) at android.app.ActivityThread.main (ActivityThread.java:7025) at java.lang.reflect.Method.invoke (Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:441) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408) Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
3785752364
commit
d5c07374ff
@ -92,14 +92,14 @@ abstract class BaseFragment : Fragment(), OnSelectedTunnelChangedListener {
|
||||
} catch (e: Throwable) {
|
||||
val error = ErrorMessages[e]
|
||||
val messageResId = if (checked) R.string.error_up else R.string.error_down
|
||||
val message = requireContext().getString(messageResId, error)
|
||||
val message = getString(messageResId, error)
|
||||
val view = view
|
||||
if (view != null)
|
||||
Snackbar.make(view, message, Snackbar.LENGTH_LONG)
|
||||
.setAnchorView(view.findViewById(R.id.create_fab))
|
||||
.show()
|
||||
else
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(activity ?: Application.get(), message, Toast.LENGTH_LONG).show()
|
||||
Log.e(TAG, message, e)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user