我正在開發一個包含具有4個選項卡的tabhost的android應用程序。所有4個選項卡導航到擴展活動組的相同類Activity1。移動到android中的活動組中的以前的活動
從活動1我又從這一新的活動,我需要在按下設備後退按鈕回來活性1導航到另一個活動活性2使用下面的代碼,
Intent intent = new Intent(arg1.getContext(), Activity2.class);
replaceContentView("sample", intent, Intent.FLAG_ACTIVITY_CLEAR_TOP);
public void replaceContentView(String id, Intent newIntent, int flag) {
View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(flag)).getDecorView();
this.setContentView(view);
現在。我overrided onbackpressed()方法中活性2與下面的代碼,
Intent intent = new Intent(this, Activity1.class);
Activity parentActivity = (Activity1)getParent();
parentActivity.replaceContentView("sample", intent, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
當我運行的代碼,它實際上搬出活性2,但它也搬出活動1中。 我需要的是從Activity2回到Activity1 ...任何人都可以幫助我嗎?
你可以解釋你使用replaceContentView()來瀏覽活動的方式..你可以簡單地開始活動並完成它。 – NaserShaikh 2013-03-01 11:48:05
因爲我希望Activity1中的選項卡顯示在新活動的頂部.... – akh 2013-03-01 12:07:59