当应用程序从暂停状态返回时,如何发现应用程序冻结?

时间:2016-06-13 13:37:12

标签: android

我的应用程序面临一种非常奇怪的行为:

  1. App正常启动;
  2. 我将该应用留给另一个应用程序或者回到手机的主屏幕;
  3. 当我尝试回到之前的应用程序实例时,它会挂起,直到我得到"应用程序没有响应,强制它关闭?";
  4. 我知道这听起来像是一些内存泄漏或循环卡住的问题,但这种行为是完全随机的(有时我执行上面的步骤两次我得到问题,有时我做了十次,直到我得到错误) 。在logcat中没有抛出异常。在监视器中,分配的内存永远不会爆炸,并且它会保持在可用内存之下。我已经使用了记忆分析器,报告中没有显示任何奇怪的内容。

    我已经注意到,当我在我的Activity中使用加载器微调器时,执行上述步骤以使应用程序崩溃所需的次数减少 - 有时只执行一次会使应用程序崩溃。

    有没有人建议我能做些什么来弄清楚可能导致这个问题的原因?

    谢谢。

    修改

    在App的任何活动中都会发生此行为,可以在以下位置找到Logcat和代码:

    我的所有活动都是此模板的后代:

    public abstract class ActivityTemplate extends AppCompatActivity {
    
        private Boolean isRunning = Boolean.TRUE;
    
        private ToolbarManager mToolbarManager;
        private ActivitySetup mSetup;
    
        public abstract ActivitySetup setUpActivity();
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mToolbarManager = new ToolbarManager();
            mSetup = setUpActivity();
            setContentView(mSetup.getContentView());
            ButterKnife.bind(this);
            prepareToolbar();
            registerForEvents();
            this.startResources();
        }
    
        private void prepareToolbar() {
            if (mSetup.getHasToolbar()) {
                mToolbarManager.initToolbar(this, mSetup.getTitle(), R.id.toolbar, R.color.textPrimary);
                if (mSetup.getDefaultReturnBehavior()) {
                    mToolbarManager.setNavigationReturnBehavior();
                }
                mToolbarManager.prepareNavigationBehavior(mSetup.getNavigationIcon(), mSetup.getOnNavigationItemClicked());
            }
        }
    
        public void startResources() {
        }
    
        @Override
        public void onDestroy() {
            this.unregisterForEvents();
            super.onDestroy();
        }
    
        @Override
        protected void onPause() {
            super.onPause();
            this.isRunning = Boolean.FALSE;
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            this.isRunning = Boolean.TRUE;
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            return super.onCreateOptionsMenu(menu);
        }
    
        public void registerForEvents() {
            Map<EventCatalog, TaskExecutor> executors = this.setEventHandlers();
            if (null != executors && executors.size() > 0) {
                for (EventCatalog event : executors.keySet()) {
                    NotificationCenter.RegistrationCenter.registerForEvent(event, executors.get(event));
                }
            }
        }
    
        public void unregisterForEvents() {
            Map<EventCatalog, TaskExecutor> executors = this.setEventHandlers();
            if (null != executors && executors.size() > 0) {
                for (EventCatalog key : executors.keySet()) {
                    NotificationCenter.RegistrationCenter.unregisterForEvent(key, executors.get(key));
                }
            }
        }
    
        public boolean isRunning() {
            return this.isRunning;
        }
    
        public Toolbar getToolbar() {
            return mToolbarManager.getToolbar();
        }
    
        public Map<EventCatalog, TaskExecutor> setEventHandlers() {
            return null;
        }
    }
    
    
    
    06-13 10:39:11.258 25215-25271/br.com.gogame I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8974_LA.BF.1.1.3_RB1__release_AU (I3193f6e94a)
                                                                   OpenGL ES Shader Compiler Version: E031.28.00.02
                                                                   Build Date: 10/09/15 Fri
                                                                   Local Branch: mybranch15039904
                                                                   Remote Branch: quic/LA.BF.1.1.3_rb1.2
                                                                   Local Patches: NONE
                                                                   Reconstruct Branch: NOTHING
        06-13 10:39:11.274 25215-25271/br.com.gogame I/OpenGLRenderer: Initialized EGL, version 1.4
        06-13 10:39:11.315 25215-25215/br.com.gogame E/RecyclerView: No adapter attached; skipping layout
        06-13 10:39:11.315 25215-25215/br.com.gogame E/RecyclerView: No adapter attached; skipping layout
        06-13 10:39:11.601 25215-25215/br.com.gogame E/RecyclerView: No adapter attached; skipping layout
        06-13 10:39:11.601 25215-25215/br.com.gogame E/RecyclerView: No adapter attached; skipping layout
        06-13 10:39:11.640 25215-25215/br.com.gogame E/RecyclerView: No adapter attached; skipping layout
        06-13 10:39:11.640 25215-25215/br.com.gogame E/RecyclerView: No adapter attached; skipping layout
        06-13 10:39:20.864 25215-25241/br.com.gogame E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/br.com.gogame-1/base.apk"],nativeLibraryDirectories=[/data/app/br.com.gogame-1/lib/arm, /data/app/br.com.gogame-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
        06-13 10:39:25.202 25575-25575/br.com.gogame:background_crash E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.crash.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/br.com.gogame-1/base.apk"],nativeLibraryDirectories=[/data/app/br.com.gogame-1/lib/arm, /data/app/br.com.gogame-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
        06-13 10:39:25.239 25575-25575/br.com.gogame:background_crash D/ChimeraCfgMgr: Reading stored module config
        06-13 10:39:25.299 25575-25575/br.com.gogame:background_crash I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:2
        06-13 10:39:25.299 25575-25575/br.com.gogame:background_crash I/DynamiteModule: Selected remote version of com.google.android.gms.crash, version >= 2
        06-13 10:39:25.312 25575-25575/br.com.gogame:background_crash W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000002/n/armeabi-v7a
        06-13 10:39:25.312 25575-25575/br.com.gogame:background_crash W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000002/n/armeabi
        06-13 10:39:25.313 25575-25575/br.com.gogame:background_crash D/ChimeraFileApk: Primary ABI of requesting process is armeabi-v7a
        06-13 10:39:25.314 25575-25575/br.com.gogame:background_crash D/ChimeraFileApk: Classloading successful. Optimized code found.
        06-13 10:39:25.334 25575-25575/br.com.gogame:background_crash I/FirebaseCrashReceiverServiceImpl: FirebaseCrashReceiverServiceImpl created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/user/0/com.google.android.gms/app_chimera/m/00000002/DynamiteModulesC_GmsCore_prodmnc_xxhdpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000002/n/armeabi-v7a, /data/user/0/com.google.android.gms/app_chimera/m/00000002/n/armeabi, /vendor/lib, /system/lib]]]
        06-13 10:39:25.340 25575-25575/br.com.gogame:background_crash D/FirebaseCrashReceiverServiceImpl: onCreate
        06-13 10:39:25.345 25575-25575/br.com.gogame:background_crash I/DynamiteModule: Considering local module com.google.android.gms.flags:0 and remote module com.google.android.gms.flags:1
        06-13 10:39:25.345 25575-25575/br.com.gogame:background_crash I/DynamiteModule: Selected remote version of com.google.android.gms.flags, version >= 1
        06-13 10:39:25.379 25575-25575/br.com.gogame:background_crash I/FirebaseCrashSenderServiceImpl: FirebaseCrashSenderServiceImpl created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/user/0/com.google.android.gms/app_chimera/m/00000002/DynamiteModulesC_GmsCore_prodmnc_xxhdpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000002/n/armeabi-v7a, /data/user/0/com.google.android.gms/app_chimera/m/00000002/n/armeabi, /vendor/lib, /system/lib]]]
        06-13 10:39:25.379 25575-25575/br.com.gogame:background_crash D/FirebaseCrashSenderServiceImpl: onCreate
        06-13 10:40:46.438 25215-25215/br.com.gogame D/FirebaseApp: Notifying background state change listeners.
        06-13 10:40:46.469 25215-25271/br.com.gogame E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb9fb34d0
        06-13 10:40:47.348 25215-26924/br.com.gogame I/DynamiteModule: Considering local module com.google.android.gms.tagmanager:1 and remote module com.google.android.gms.tagmanager:2
        06-13 10:40:47.348 25215-26924/br.com.gogame I/DynamiteModule: Selected remote version of com.google.android.gms.tagmanager, version >= 2
        06-13 10:40:47.428 25215-25215/br.com.gogame D/FirebaseApp: Notifying background state change listeners.
        06-13 10:40:47.738 25215-26924/br.com.gogame W/GoogleTagManager: Tag Manager's event handler WILL NOT be installed (no container loaded)
        06-13 10:40:48.273 25215-25271/br.com.gogame E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb9f87b18
        06-13 10:40:48.296 25215-25215/br.com.gogame D/FirebaseApp: Notifying background state change listeners.
    06-13 10:44:08.361 25215-25221/br.com.gogame I/art: Thread[2,tid=25221,WaitingInMainSignalCatcherLoop,Thread*=0xb9ce2a10,peer=0x12d270a0,"Signal Catcher"]: reacting to signal 3
    06-13 10:44:08.713 25215-25221/br.com.gogame I/art: Wrote stack traces to '/data/anr/traces.txt'
    

    编辑2

    看起来这个问题与使用Firebase和Google服务有关,但是,我需要在我的应用程序中同时使用。我使用它们的方式是:

    在顶级gradle文件中:      classpath&#39; com.google.gms:google-services:3.0.0&#39;

    在我的应用程序gradle文件中:

    apply plugin: 'com.android.application'
    apply plugin: 'com.neenbedankt.android-apt'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"
    
        dexOptions {
            javaMaxHeapSize "4g"
        }
    
        defaultConfig {
            applicationId "br.com.gogame"
            minSdkVersion 21
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
            multiDexEnabled true
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        testCompile 'junit:junit:4.12'
        testCompile 'org.mockito:mockito-core:1.10.19'
    
        // GOOGLE LIBRARIES
        compile 'com.android.support:appcompat-v7:23.4.0'
        compile 'com.android.support:recyclerview-v7:23.4.0'
        compile 'com.android.support:cardview-v7:23.4.0'
        compile 'com.android.support:design:23.4.0'
        compile 'com.google.firebase:firebase-messaging:9.0.0'
        compile 'com.google.guava:guava:18.0'
        compile 'com.google.code.gson:gson:2.4'
        compile 'com.google.dagger:dagger:2.1'
        compile 'com.android.volley:volley:1.0.0'
    
        // APACHE LIBRARIES
        compile 'org.apache.httpcomponents:httpmime:4.0-alpha3'
    
        // OWN THIRD LIBRARIES
        compile 'br.com.instachat:emoji-library:1.0.6'
        compile 'br.com.edsilfer:kiwi:1.0.8'
    
        // THIRD PART LIBRARIES
        compile 'com.mikhaellopez:circularimageview:2.0.2'
        compile 'com.squareup.picasso:picasso:2.5.2'
        compile 'com.github.vajro:MaterialDesignLibrary:1.6'
        compile 'com.ogaclejapan.smarttablayout:library:1.6.0@aar'
        compile 'com.github.rey5137:material:1.2.2'
        compile 'com.appyvet:materialrangebar:1.3'
        compile 'com.github.afollestad.material-dialogs:core:0.8.5.6@aar'
        compile 'com.wang.avi:library:1.0.5'
        compile 'com.nineoldandroids:library:2.4.0'
        compile 'com.mikepenz:aboutlibraries:5.6.5@aar'
        compile 'com.jakewharton:butterknife:8.0.1'
        compile 'com.wdullaer:materialdatetimepicker:2.3.0'
        compile 'javax.inject:javax.inject:1'
        compile 'com.github.satyan:sugar:1.5'
        compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.15'
        compile 'com.yalantis:ucrop:1.5.0'
    
        apt 'com.jakewharton:butterknife-compiler:8.0.1'
        apt 'com.google.dagger:dagger-compiler:2.1'
    
        provided 'javax.annotation:jsr250-api:1.0'
    }
    
    apply plugin: 'com.google.gms.google-services'
    

1 个答案:

答案 0 :(得分:2)

好的,所以关注@ApplicationDeveloper提示,我已经从我的项目中删除了compile 'com.google.android.gms:play-services:9.0.0',它不在我的主项目中,而是在库模块中。它解决了这个问题。