简体   繁体   English

Android API 23 startActivity错误

[英]android api 23 startActivity error

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: 广播接收器在AndroidManifest.xml的内部标签中声明,如下所示:

    <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: build.gradle看起来像:

apply plugin: 'com.android.application' 应用插件:“ 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. 使用Android Studio最新的稳定版本。 was tried to restart workstation and Studio (including cache invalidation), reinstall platform, switch to beta Studio version, but have same result. 试图重新启动工作站和Studio(包括缓存无效),重新安装平台,切换到beta Studio版本,但结果相同。

will be appreciate for any suggestions for this problem. 对于这个问题的任何建议将不胜感激。 never saw something like this before. 以前从未见过这样的事情。

be calm and look all project code. 保持冷静,并查看所有项目代码。 i find a duplicate of android.content.Context class in local project's files tree. 我在本地项目的文件树中找到了android.content.Context类的副本。 And there was no startActivity method. 而且没有startActivity方法。

duplicate was added to access hidden/system only class fields/methods without java reflection. 添加重复项以访问隐藏/仅系统类字段/方法,而无需Java反射。 i'm very very sorry. 我非常非常抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM