2012-11-06 71 views
0

我不知道如何描述這個。 我有兩個活動充滿了鏈接(對其他活動),就像菜單或列表。 基本上,我可以拆分「物理」和「數學」的鏈接(是的,我需要這個教育)。 我改變了我的動作條兩個環節,就像這樣:在操作欄中需要幫助

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:id="@+id/menu_settings" 
     android:orderInCategory="100" 
     android:showAsAction="never" /> 
    <item 
     android:id="@+id/maths" 
     android:title="@string/maths" 
     android:orderInCategory="1" 
     android:showAsAction="always|withText" 
     android:titleCondensed="@string/maths" 
     android:icon="@drawable/ic_action_calculator" /> 
    <item 
     android:id="@+id/physics" 
     android:icon="@drawable/ic_action_line_chart" 
     android:title="@string/physics" 
     android:orderInCategory="2" 
     android:showAsAction="always|withText"/> 
</menu> 

一切是偉大的工作,我喜歡我的應用程序底部的「標籤」。 下面的代碼是工作壓力太大:

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_home, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case R.id.maths: 
      return true; 
     case R.id.physics: 
      Intent myIntent2 = new Intent(Home.this, ActivityPhysics.class); 
      startActivity(myIntent2); 
     default: 
      return super.onOptionsItemSelected(item); 
    } 
} 

正如你可以看到,在「數學」點擊後它什麼都不做,因爲我的數學是已。

當點擊「物理」它打開ActivityPhysics。

我的問題是,當我點擊物理學,然後去物理學,然後點擊數學,然後去數學,很多次,我必須按下後退按鈕一堆,然後回到數學和回物理...(?明白了,我的意思對不起,我是德國人:d)

呀,而且「背背背背」吸:)

回答

0

好了,所以我張貼這種問題直接與答案,因爲在寫作時,我有一個親切的想法:D 我看到了「向上」按鈕的代碼(如在Gmail等)。只需將「go to home.java」替換爲「go up,這就是home.java」。

所以系統認爲,它是不是一個鏈接到另一個活動時,它就像一個「後退」按鈕:)

所以你要替換此:

Intent myIntent2 = new Intent(ActivityPhysics.this, Home.class); 
startActivity(myIntent2); 

有了這個:

Intent intent = new Intent(this, Home.class); 
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
startActivity(intent); 

這爲我工作,使用的minSdkVersion 14 :)