android api 23 startActivity error

383 views Asked by At

have build error for sample below:

public class BootReceiver extends BroadcastReceiver {

public BootReceiver() {
}

@Override
public void onReceive(final Context mContext, Intent intent) {
    if(intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)){
        final Intent l = new Intent();
        l.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        l.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        l.setComponent(new ComponentName(this.getClass().getName(), MainActivity.class.getName()));
        mContext.getApplicationContext().startActivity(l);
    }
}
}

broadcast receiver is declared in AndroidManifest.xml inside tag like this:

    <receiver
        android:name=".BootReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter >
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>

build.gradle is looks like:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '25.0.2'
defaultConfig {
    minSdkVersion 23
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }
    debug {

    }
}
productFlavors {
}
}

dependencies {
    compile 'com.android.support:leanback-v17:23.2.1'
    compile 'com.android.support:preference-leanback-v17:23.2.1'
}

but after clean project any make attempt is followed by:

Error:(38, 37) error: cannot find symbol method startActivity(Intent)

using Android Studio latest stable release. was tried to restart workstation and Studio (including cache invalidation), reinstall platform, switch to beta Studio version, but have same result.

will be appreciate for any suggestions for this problem. never saw something like this before.

1

There are 1 answers

0
bershadskiy On BEST ANSWER

be calm and look all project code. i find a duplicate of android.content.Context class in local project's files tree. And there was no startActivity method.

duplicate was added to access hidden/system only class fields/methods without java reflection. i'm very very sorry.