2016-01-19 227 views
1

我在我的應用程序操作欄上的操作(導航上)到自定義活動?

我已經給了許多活動這個

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

ActionBar actionBar = getSupportActionBar(); 
if (actionBar != null) { 
    actionBar.setDisplayHomeAsUpEnabled(true); 
} 

回到首頁其他活動

像下面

enter image description here

如果我按下這三個按鈕,所有菜單正在工作 這是我的選項菜單

@覆蓋 公共布爾onOptionsItemSelected(菜單項項){

int id = item.getItemId(); 

if (id == R.id.abc) { 
    Intent mypIntent = new Intent(this, abc.class); 
    startActivity(mypIntent); 
    return true; 
    } 

else if (id == R.id.web) { 
    Intent webIntent = new Intent(this, Web.class); 
    startActivity(webIntent); 
    return true; 
} 
else if (id == R.id.about) { 
    Intent aboutIntent = new Intent(this, About.class); 
    startActivity(aboutIntent); 
    return true; 
} 
. 
. 
. 
.. 

return super.onOptionsItemSelected(item); 
} 

這裏並沒有一個名爲id == R.id.loginid == R.id.home菜單,但它要登錄幾天就回來了去了家活動

,但如果我按回..回行動就是重定向到登錄首頁的

我一直在使用共享prefe增加了一個登錄頁面,我的應用程序頁面研究所-ED分配辦法..它現在是發射活動..

在這裏我登錄活動上如果一旦用戶登錄,應該它應該重定向到主頁上的活動,每次.. 及其工作很好..

但在操作欄,當我按下箭頭按鈕,它重定向到空的登錄頁面.. 如果我按取消整個應用程序的工作..我的資格,除了這個動作條安全..

更新

我也給出了Intent如果憑據登錄成功重定向到主頁上的活動應用程序啓動時,它會檢查每一次

每一件事情是作爲用於細除了動作回

如何解決這個問題?

+0

是否在HomeActivity上有後退按鈕? – kevz

+0

在家庭活動沒有後退按鈕..我有更多的其他活動..就像網站有關...等行動吧,如果我按回它的重定向到登錄..爲什麼不回家...在添加登錄頁面之前,它要回家...但現在它的重定向到發射器即...登錄.. –

+0

wt的應用程序的最小sdk? – kevz

回答

1

好吧確保ü做如下聲明活動 - 在每一個活動

<activity 
    android:name="com.example.myfirstapp.DisplayMessageActivity" 
    android:parentActivityName="com.example.myfirstapp.MainActivity" > 
    <!-- The meta-data element is needed for versions lower than 4.1 --> 
    <meta-data 
     android:name="android.support.PARENT_ACTIVITY" 
     android:value="com.example.myfirstapp.MainActivity" /> 
</activity> 

現在添加下面的代碼塊級

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
switch (item.getItemId()) { 
// Respond to the action bar's Up/Home button 
case android.R.id.home: 
    NavUtils.navigateUpFromSameTask(this); 
    return true; 
} 
return super.onOptionsItemSelected(item); 
} 

更新 添加一個新的類文件檢查登錄或不使用家默認..並替換您的新班級launcherManifest

+0

是的,我在清單..幾天就回來了工作的罰款鑑於這個..但現在它重定向到啓動活動..看到我更新的問題,我想在動作條不回選項菜單.. –

+0

@別是負的:以及那個android按鈕rt?並且你可以在onOptionItemSelected()中獲得它的onclick,這樣就可以有效地完成它了。 – kevz

+0

,但我要爲後面button..not選項按鈕 –

0

只需重寫此方法。

@Override 
public boolean onOptionsItemSelected(MenuItem item) 
{ 
    switch (item.getItemId()) 
    { 
     case android.R.id.home: 
     { 
      Intent intent = new Intent(mContext, Activity.class);/*your activity name*/ 
     startActivity(intent); 
     } 
     default: 
      return super.onOptionsItemSelected(item); 
    } 
} 
+0

它的好,但我已經給出了這個'if(id == R.id.web1)意圖webIntent =新的意圖(this,Web.class); startActivity(webIntent); 返回true;如果(id == R.id.about1){ } startActivity(aboutIntent); 返回true; }'我需要在後退箭頭按鈕,, –

+0

任何你想要的活動重定向到只是你自己的類 – Nilabja

+0

你應該不會首發活動取代Activity.class又怎麼把它已經在堆棧 – kevz