2016-04-26 87 views
0

我有一個活動,只要調用onBackPressed或onOptionsItemSelected,就可以調用上一個活動。我的代碼正在開發Kitkat,冰淇淋和棉花糖。它只是在棒棒糖不工作。這是爲什麼?OnBackPressed和onOptionsItemSelected在棒棒糖中不工作

我的動態

@Override 
public void onBackPressed() { 
    super.onBackPressed(); 

} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    super.onOptionsItemSelected(item); 
    return NavUtils.navigateUpFromSameTask(this); 

} 

Android清單

<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

您的代碼在哪裏返回onOptionsItemSelected()中的上一個活動?我的意思是,onBackPressed很清楚,它會自動執行,但是在選擇的項目中,必須有一些finish()調用或liek我在Manifest中看到一些'NavUtils.navigateUpFromSameTask(this);'調用 – Opiatefuchs

+0

'lollipop' ? 'logcat'? – Max

+0

不要重寫onBackPressed(){ – Haroon

回答

0

onOptionsItemSelected是當你要調用invalidateOptionsMenu()被召回的方法。