android10 crash,Android 10 Activity onCreate Crash

问题

The splash activity of my app works well on all devices except on an Android 10 device that I have just recently updated.

Here is my code:

public class SplashScreen extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

if(FirebaseAuth.getInstance().getUid() != null)

startActivity(new Intent(this, HomeActivity.class));

else

startActivity(new Intent(this, LoginActivity.class));

finish();

}

}

I have also tried navigating directly to HomeActiviy or LoginActivity but still crashes when I try to run on an Android 10 device

Error occurs when calling super.onCreate(savedInstanceState)

2020-01-17 13:58:25.527 23561-23561/? E/AndroidRuntime: FATAL EXCEPTION: main

Process: rickroydaban.projects.android.memorise, PID: 23561

java.lang.RuntimeException: Unable to start activity ComponentInfo{rickroydaban.projects.android.memorise/rickroydaban.android.memorise.ui.SplashScreen}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.lifecycle.ReportFragment.setProcessListener(androidx.lifecycle.ReportFragment$ActivityInitializationListener)' on a null object reference

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3448)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)

at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)

at android.os.Handler.dispatchMessage(Handler.java:107)

at android.os.Looper.loop(Looper.java:237)

at android.app.ActivityThread.main(ActivityThread.java:7811)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.lifecycle.ReportFragment.setProcessListener(androidx.lifecycle.ReportFragment$ActivityInitializationListener)' on a null object reference

at androidx.lifecycle.ProcessLifecycleOwner$3.onActivityCreated(ProcessLifecycleOwner.java:162)

at android.app.Application.dispatchActivityCreated(Application.java:392)

at android.app.Activity.dispatchActivityCreated(Activity.java:1232)

at android.app.Activity.onCreate(Activity.java:1513)

at androidx.core.app.ComponentActivity.onCreate(ComponentActivity.java:81)

at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:149)

at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:313)

at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)

at rickroydaban.android.memorise.ui.SplashScreen.onCreate(SplashScreen.java:18)

at android.app.Activity.performCreate(Activity.java:7955)

at android.app.Activity.performCreate(Activity.java:7944)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3423)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)

at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)

at android.os.Handler.dispatchMessage(Handler.java:107)

at android.os.Looper.loop(Looper.java:237)

at android.app.ActivityThread.main(ActivityThread.java:7811)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

Has anyone able to fix this issue?

回答1:

As per this issue, this will occur when using lifecycle-runtime:2.2.0 (usually through a transitive dependency on Fragment or AppCompat) and lifecycle-process:2.1.0 (usually through a transitive dependency on lifecycle-extensions).

There are a number of work arounds available in the bug:

You do any one of the following:

Add an explicit dependency on lifecycle-process:2.2.0-alpha05 to pull in the new version that is compatible with lifecycle-runtime:2.2.0-alpha05

Upgrade your lifecycle:extensions dependency to 2.2.0-alpha05 so that lifecycle-process is upgraded

Remove the lifecycle:extensions dependency entirely and use only the lifecycle libraries you need (for example, use lifecycle-viewmodel-ktx if you want ViewModels) so that you don't pull in lifecycle-process at all

Or, since the compatibility issue has been fixed in a later release, upgrade to a later version of Fragments (version 1.2.0-beta01 or higher) or Lifecycle 2.2.0-beta01 or higher if you directly depend on Lifecycle.

来源:https://stackoverflow.com/questions/59782060/android-10-activity-oncreate-crash

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值