Android应用程序在执行时崩溃" startservice()"在sdk 25及更低

时间:2018-03-12 10:10:45

标签: android

在我的应用中,我使用service class来获取来自我服务器的同步数据。它适用于所有类型的设备之前正常工作。现在它仅适用于 26 + SDK设备,并且在 25 和更低SDK时被粉碎。执行startService(intent)时,它会被粉碎。并且在try catch中无法获得任何异常。

  

这是我的活动代码:

try {
                if(!isMyServiceRunning(SyncdataService.class)){
                    Intent intent = new Intent(this, SyncdataService.class);
                    stopService(intent);
                    startService(intent);
                }
            }catch (Exception e){
                Log.d("Exception", "Error: " + e.toString());
            }
  

这是我的Gradel:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.catalystconnect.catalystconnect"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    useLibrary 'org.apache.http.legacy'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })


    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support:support-vector-drawable:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:26.+'
    compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.1.+'
    compile 'me.leolin:ShortcutBadger:1.1.8'
    compile 'com.google.firebase:firebase-core:10.0.1'
    testCompile 'junit:junit:4.12'


    compile 'com.twilio:voice-android:2.0.4'
    compile 'com.android.support:design:26.0.2'
    compile 'com.android.support:appcompat-v7:26.0.2'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.koushikdutta.ion:ion:2.1.8'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
}

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

为什么会这样?

0 个答案:

没有答案