我有一个活动,只要在调用onBackPressed或onOptionsItemSelected时调用前一个活动。我的代码正在开发Kitkat,Ice cream和Marshmallow。它只能在 Lollipop 中使用。这是为什么?
我的活动
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
return NavUtils.navigateUpFromSameTask(this);
}
Android Manifest
<activity
android:name=".Activities.ReminderActivity"
android:screenOrientation="portrait"
android:label="@string/title_reminder_activity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Activities.MainActivity" />
</activity>
build.grade
apply plugin: 'com.android.application'
apply from: "quality.gradle"
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.pointwest.timetrackermobilelog"
vectorDrawables.useSupportLibrary = true
minSdkVersion 15
targetSdkVersion 23
versionCode 36
versionName "1.0"
multiDexEnabled true
}
repositories {
maven { url "https://jitpack.io" }
jcenter()
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
ext {
supportLibVersion = '23.2' // variable that can be referenced to keep support libs consistent
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.2.+'
compile 'com.android.support:design:23.2.+'
compile 'com.android.support:cardview-v7:23.2.+'
compile 'com.android.support:recyclerview-v7:23.2.+'
compile "com.android.support:support-v4:23.2.+"
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.jpardogo.materialtabstrip:library:1.1.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'io.realm:realm-android:0.82.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.h6ah4i.android.materialshadowninepatch:materialshadowninepatch:0.6.3'
compile 'me.zhanghai.android.materialprogressbar:library:1.1.5'
compile 'com.code-troopers.betterpickers:library:2.5.3'
}
答案 0 :(得分:0)
onOptionsItemSelected
是一种在您打算致电invalidateOptionsMenu()
时会被召回的方法。