gpt4 book ai didi

android - Android App在长时间闲置时不断崩溃(API 24和23)

转载 作者:行者123 更新时间:2023-12-03 16:46:50 24 4
gpt4 key购买 nike

我面临一个有线问题,我的应用程序在空闲时(按锁定屏幕按钮后)始终会崩溃,但仅在API 24和23上我才在棒棒糖及以下测试过它,并且仍能正常恢复

我遇到有关新电池优化系统Doze的文档

但是据我了解,Activity生命周期(OnPause,OnResume ...)具有这种优势。

PS:我仅通过一个简单的YouTube Activity 进行了测试,没有其他组件,但是它仍然崩溃

Java源码

public class PlayerActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

private YouTubePlayer youTubePlayer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
// Initializing YouTube player view
YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
youTubePlayerView.initialize(Constants.YOUTUBE_API_KEY, this);
}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
if(null== youTubePlayer) return;
this.youTubePlayer = youTubePlayer;
// Start buffering
if (!wasRestored) {
youTubePlayer.loadVideo("gsjtg7m1MMM");
}
}

@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {

}

@Override
protected void onDestroy() {
super.onDestroy();
youTubePlayer = null;
}

}

布局:
FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"

app:layout_behavior="@string/appbar_scrolling_view_behavior"

tools:showIn="@layout/activity_player">

<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
09-13 13:03:29.936 21317-21317/info.digibox.replaytv E/Parcel: Class not found when unmarshalling: aps
java.lang.ClassNotFoundException: aps
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:400)
at android.os.Parcel.readParcelableCreator(Parcel.java:2517)
at android.os.Parcel.readParcelable(Parcel.java:2471)
at android.os.Parcel.readValue(Parcel.java:2374)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:2808)
at android.os.Parcel.readSparseArray(Parcel.java:2077)
at android.os.Parcel.readValue(Parcel.java:2431)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2727)
at android.os.BaseBundle.unparcel(BaseBundle.java:269)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:910)
at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2262)
at android.app.Activity.onRestoreInstanceState(Activity.java:1128)
at android.app.Activity.performRestoreInstanceState(Activity.java:1083)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1182)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.ClassNotFoundException: Didn't find class "aps" on path: DexPathList[[zip file "/data/app/info.digibox.replaytv-1/base.apk"],nativeLibraryDirectories=[/data/app/info.digibox.replaytv-1/lib/arm, /data/app/info.digibox.replaytv-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:400) 
at android.os.Parcel.readParcelableCreator(Parcel.java:2517) 
at android.os.Parcel.readParcelable(Parcel.java:2471) 
at android.os.Parcel.readValue(Parcel.java:2374) 
at android.os.Parcel.readSparseArrayInternal(Parcel.java:2808) 
at android.os.Parcel.readSparseArray(Parcel.java:2077) 
at android.os.Parcel.readValue(Parcel.java:2431) 
at android.os.Parcel.readArrayMapInternal(Parcel.java:2727) 
at android.os.BaseBundle.unparcel(BaseBundle.java:269) 
at android.os.Bundle.getSparseParcelableArray(Bundle.java:910) 
at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2262) 
at android.app.Activity.onRestoreInstanceState(Activity.java:1128) 
at android.app.Activity.performRestoreInstanceState(Activity.java:1083) 
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1182) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6776) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) 

09-13 13:03:29.939 21317-21317 / info.digibox.replaytv D / AndroidRuntime:关闭VM
09-13 13:03:29.941 21317-21317 / info.digibox.replaytv E / UncaughtException:java.lang.RuntimeException:无法启动 Activity ComponentInfo {info.digibox.replaytv / info.digibox.replaytv.activities.PlayerActivity}: android.os.BadParcelableException:解组时的ClassNotFoundException:APS
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
在android.app.ActivityThread.-wrap14(ActivityThread.java)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1642)
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:154)
在android.app.ActivityThread.main(ActivityThread.java:6776)
在java.lang.reflect.Method.invoke(本机方法)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1496)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
由以下原因导致:android.os.BadParcelableException:解组时的ClassNotFoundException:aps
在android.os.Parcel.readParcelableCreator(Parcel.java:2545)
在android.os.Parcel.readParcelable(Parcel.java:2471)
在android.os.Parcel.readValue(Parcel.java:2374)
在android.os.Parcel.readSparseArrayInternal(Parcel.java:2808)
在android.os.Parcel.readSparseArray(Parcel.java:2077)
在android.os.Parcel.readValue(Parcel.java:2431)
在android.os.Parcel.readArrayMapInternal(Parcel.java:2727)
在android.os.BaseBundle.unparcel(BaseBundle.java:269)
在android.os.Bundle.getSparseParcelableArray(Bundle.java:910)
在com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2262)
在android.app.Activity.onRestoreInstanceState(Activity.java:1128)
在android.app.Activity.performRestoreInstanceState(Activity.java:1083)
在android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1182)
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
在android.app.ActivityThread.-wrap14(ActivityThread.java)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1642)
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:154)
在android.app.ActivityThread.main(ActivityThread.java:6776)
在java.lang.reflect.Method.invoke(本机方法)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1496)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
09-13 13:03:29.947 21317-21359 / info.digibox.replaytv I / FA:找不到标签管理器,因此将无法使用
09-13 13:03:29.950 21317-21359 / info.digibox.replaytv D / FA:记录事件(FE):app_exception(_ae), bundle 包[{firebase_event_origin(_o)= crash,时间戳= 1505307809942,致命= 1} ]
09-13 13:03:29.967 21317-21359 / info.digibox.replaytv V / FA:使用测量服务
09-13 13:03:29.967 21317-21359 / info.digibox.replaytv V / FA:连接尝试已在进行中
09-13 13:03:30.205 21317-21317 / info.digibox.replaytv E / AndroidRuntime:FATAL EXCEPTION:main
流程:info.digibox.replaytv,PID:21317
java.lang.RuntimeException:无法启动 Activity ComponentInfo {info.digibox.replaytv / info.digibox.replaytv.activities.PlayerActivity}:android.os.BadParcelableException:ClassNotFoundException,当解组时:aps
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
在android.app.ActivityThread.-wrap14(ActivityThread.java)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1642)
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:154)
在android.app.ActivityThread.main(ActivityThread.java:6776)
在java.lang.reflect.Method.invoke(本机方法)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1496)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
由以下原因导致:android.os.BadParcelableException:解组时的ClassNotFoundException:aps
在android.os.Parcel.readParcelableCreator(Parcel.java:2545)
在android.os.Parcel.readParcelable(Parcel.java:2471)
在android.os.Parcel.readValue(Parcel.java:2374)
在android.os.Parcel.readSparseArrayInternal(Parcel.java:2808)
在android.os.Parcel.readSparseArray(Parcel.java:2077)
在android.os.Parcel.readValue(Parcel.java:2431)
在android.os.Parcel.readArrayMapInternal(Parcel.java:2727)
在android.os.BaseBundle.unparcel(BaseBundle.java:269)
在android.os.Bundle.getSparseParcelableArray(Bundle.java:910)
在com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2262)
在android.app.Activity.onRestoreInstanceState(Activity.java:1128)
在android.app.Activity.performRestoreInstanceState(Activity.java:1083)
在android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1182)
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
在android.app.ActivityThread.-wrap14(ActivityThread.java)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1642)
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:154)
在android.app.ActivityThread.main(ActivityThread.java:6776)
在java.lang.reflect.Method.invoke(本机方法)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1496)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
09-13 13:03:30.218 21317-21422 / info.digibox.replaytv I / FirebaseCrash:发送崩溃

在格式化要点格式 here时遇到问题
提前致谢

最佳答案

取消对aps的 bundle 时,找不到名为Parcelable的类。在文件中查找“aps”,以查看您的代码中是否有对此类的提及。

另外,它是否发生在调试或发布中?如果已发布,是否有可能在构建中启用了Proguard(调试构建也可能是这种情况,只是不太常见)?

尝试不存储私有(private)字段YouTubePlayer youTubePlayer:

public class PlayerActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
// Initializing YouTube player view
YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
youTubePlayerView.initialize(Constants.YOUTUBE_API_KEY, this);
}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
if(null== youTubePlayer) return;
// Start buffering
if (!wasRestored) {
youTubePlayer.loadVideo("gsjtg7m1MMM");
}
}

@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {

}
}

关于android - Android App在长时间闲置时不断崩溃(API 24和23),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46198706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com