android api 23 startActivity 错误
android api 23 startActivity error
以下示例存在构建错误:
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);
}
}
}
广播接收器在 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 看起来像:
应用插件:'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'
}
但是在清理项目之后,任何 make 尝试之后都是:
Error:(38, 37) error: cannot find symbol method startActivity(Intent)
使用 Android Studio 最新稳定版。
尝试重启工作站和 Studio(包括缓存失效),重装平台,切换到 Beta Studio 版本,但结果相同。
如果您对此问题有任何建议,我们将不胜感激。以前从未见过这样的东西。
静下心来查看所有项目代码。我在本地项目的文件树中找到了 android.content.Context
class 的副本。而且没有startActivity
方法。
添加了重复项以访问 hidden/system 仅 class fields/methods 而没有 java 反射。非常非常抱歉。
以下示例存在构建错误:
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);
}
}
}
广播接收器在 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 看起来像:
应用插件:'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'
}
但是在清理项目之后,任何 make 尝试之后都是:
Error:(38, 37) error: cannot find symbol method startActivity(Intent)
使用 Android Studio 最新稳定版。 尝试重启工作站和 Studio(包括缓存失效),重装平台,切换到 Beta Studio 版本,但结果相同。
如果您对此问题有任何建议,我们将不胜感激。以前从未见过这样的东西。
静下心来查看所有项目代码。我在本地项目的文件树中找到了 android.content.Context
class 的副本。而且没有startActivity
方法。
添加了重复项以访问 hidden/system 仅 class fields/methods 而没有 java 反射。非常非常抱歉。