单击后退按钮时,Activity正在重新启动

时间:2017-06-05 07:39:16

标签: android android-intent android-activity

我正在使用这样的意图开始一项活动:

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();
}
}

2 个答案:

答案 0 :(得分:0)

在第二项活动中试试这个

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

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

答案 1 :(得分:-1)

使用以下代码......

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

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