2

The app I'm developing works with no problem on emulator, but when I install the debug apk on a device, it takes 30 secs or maybe a minute to open for the first time (white screen for the entire time), and when finally it shows something and the app runs, it first shows me an error that the app takes too long, I choose to ignore it since the app finally show something. When it finally works for the first time, it runs with no problem at all. This only happened THE FIRST TIME the app is opened after installation.

So in summary:

  1. The app works great on emulator.

  2. The app is installed with no problem.

  3. The first time the app is opened it shows nothing but a full white screen.

  4. The app finally works just like in the emulator.

  5. Shortly after the app starts working, the device shows me an error, to close or wait for the app.

  6. After ignoring the error, the app works with no problem at all, all services working.

  7. If the app is closed and opened again, it works perfectly.

Note: This app have multiDexEnabled true, I know this may be the cause, but in the emulator works fine.

Thanks for all the help you can give me here.

EDIT: Some more infor about the app: It uses maps, and firebae to give user notifications. The map service and activity is called only when the user enters the activity, firebase service on the other hand, is called when the app runs. this is the gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.example.andres.redfutbol"
        multiDexEnabled true
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'



    compile 'com.android.support:appcompat-v7:24.1.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.firebase:firebase-messaging:9.0.2'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.android.support:design:24.1.0'
    //compile 'com.google.android.gms:play-services:9.2.1'
    compile 'com.google.android.gms:play-services:9.0.2'

}
apply plugin: 'com.google.gms.google-services'

Please if you need more information let me know. And i dont think this is a dublicate question as suggested below, that question is about the emulator, and as i mentioned before, in my case, my app runs fast and good in the emulator, is when i tested it in a real device when this problem happened, and to mention it again, it only happened THE FIRST TIME the app is opened after installation, later, i can close it, open it and close it again, it will work fine.

Felipe
  • 63
  • 7
  • Your app must be doing too much work in the main thread, tell a bit more about the features in your app. – RamithDR Sep 13 '16 at 03:10
  • Possible duplicate of [The application may be doing too much work on its main thread](http://stackoverflow.com/questions/14678593/the-application-may-be-doing-too-much-work-on-its-main-thread) – RamithDR Sep 13 '16 at 03:12
  • You guys seem to be missing the point. He says it works FINE on on the second, third, fourth runs.... if the problem was 'too much work on the main thread' then why would it only run badly on the first run? But yeah, dude... you kinda need to put a little more info. – Nerdy Bunz Sep 13 '16 at 03:50

2 Answers2

0

this bug happend to me too, it was working great until i removed three import codes from my main activity code

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Menu;
import android.widget.TextView;

unfortunatly i dont know the codes and now i have same problem but i remember on one of them has "java" word in it and another one has "protected" word in it.

god why i removed them

i fixed this problem by recreate all codes from the begining i think we shouldnt remove import codes because the merging app will not remove them so phone wants more time to remove useless docs and start the app.

0

No need to replace or edit any gradle build link, It taking load when User first time app is installed. This is happening in all type of Applications like Whatsapp, Linkedin, etc. So Don't worry.

Narendra Sorathiya
  • 3,770
  • 2
  • 34
  • 37