2017-06-05 83 views
1

我使用的意圖是這樣開始的活動:在單擊後退按鈕活動正在重新啓動本身

Bundle bundle = new Bundle(); 
bundle.putParcelableArrayList("datacover",arrayList); 
Intent intent = new Intent(TroubleShootActivity.this,SearchResultsActivity.class); 
intent.putExtra("bundle",bundle); 
startActivity(intent); 

我不是整理活動,但仍當我在一個活動上單擊後退按鈕,它不返回到以前的活動,而是重新啓動自己。

代碼的其他活動:下面的代碼

public class SearchResultsActivity extends AppCompatActivity implements InnerDetailsFragment.OntroubleshootinneritemsListener,InnerDetailsFragment.OnHandleBack,CompleteDetailsFragment.OnHandleBack { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_search_results); 
    if(!getResources().getBoolean(R.bool.twoPaneMode)){ 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
    }else{ 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
    } 

    Bundle bundle=getIntent().getBundleExtra("bundle"); 

    FragmentManager fragmentManager = getSupportFragmentManager(); 
    Fragment Inner = new InnerDetailsFragment(); 
    bundle.putString("val", "search"); 
    Inner.setArguments(bundle); 
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction().replace(R.id.activity_search_results,Inner); 

    fragmentTransaction.commit(); 


} 

@Override 
public void onBackClick(String inner) { 
    super.onBackPressed(); 
} 

@Override 
public void ontroubleinneritemelected(int position, String heading, CoverageData coverageData) { 
    Bundle bundle = new Bundle(); 
    bundle.putParcelable("coverage",coverageData); 

    FragmentManager fragmentManager = getSupportFragmentManager(); 
    Fragment Detailsf= new CompleteDetailsFragment(); 
    Detailsf.setArguments(bundle); 
    FragmentTransaction ft = fragmentManager.beginTransaction().replace(R.id.activity_search_results,Detailsf); 
    ft.addToBackStack("completedetails"); 
    ft.commit(); 

} 

@Override 
public void onBackPressed() { 
    super.onBackPressed(); 
} 
} 
+0

使用finish()代替super.onBackPressed(); –

+0

你能分享InnerDetailsFragment嗎?或者這3個聽衆。 – JavadKhan

+0

根本不覆蓋後退按鈕。不知道你從中獲得什麼 – Doomsknight

回答

-1

使用...

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

    Intent i=new Intent(CurrentActivity.this, PreviousActivity.class); 
    startActivity(i); 
} 
0

剛剛嘗試這一點在第二活動

@Override 
public void onBackPressed() { 
    finish(); 
} 

fragmentManager.beginTransaction()。添加(R.id.activity_search_results,Detailsf); ft.commit();

+0

有兩個片段,如果我第二個片段後面應該來到第一個片段,如果我添加完成();它會直接從第二個片段中退出活動。 –

+0

FragmentManager fragmentManager = getSupportFragmentManager(); Fragment Detailsf = new CompleteDetailsFragment(); Detailsf.setArguments(bundle); FragmentTransaction ft = fragmentManager.beginTransaction()。add(R.id.activity_search_results,Detailsf); ft.addToBackStack(「completedetails」); ft.commit(); – Meikiem

+0

在這部分代碼中代替try try add。 – Meikiem

相關問題