简体   繁体   English

Android-如何动态转移到活动或先前的活动?

[英]Android - How to move to activity dynamically or previous activity?

I have 3 activities , Activity A and Activity B both can access to Activity C. But at a time,I am using Intent to return back to previous activity. 我有3个活动,活动A和活动B都可以访问活动C。但是一次,我正在使用Intent返回到先前的活动。

Intent i = new Intent(C.this , A.class); 意图i =新意图(C.this,A.class);

Here i use activity C to return back to Activity A. but i want to return to activity A or B from C depending upon who called it. 在这里,我使用活动C返回活动A。但是我想从C返回活动A或B,具体取决于谁调用它。 Not using finish(); 不使用finish(); to return back to activity. 返回活动。

If A calls C then intent i = new Intent (C.this, "dynamically set A"); 如果A调用C,则intent i = new Intent (C.this, "dynamically set A");

If B calls C then intent i = new Intent (C.this, "dynamically set B"); 如果B调用C,则intent i = new Intent (C.this, "dynamically set B");

在第一个通话中传递一个捆绑包(从A到C或从B到C),并在单击后退操作时检查它的来源。

You can simply use finish() method without using the intent. 您可以简单地使用finish()方法,而无需使用意图。 Look at this: 看这个:

Button button = this.findViewById(R.id.backButton);
button.setOnClickListener(new OnClickListener() {
  @Override
  public void onClick(View v) {
    finish();
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM