android - 将烤面包从一项活动传递给另一项活动

不确定这是否有效,但我正尝试从CustomerCall活动向Toledo活动发送Toast消息。android - 将烤面包从一项活动传递给另一项活动

一旦司机选择取消。敬酒需要发送到RiderHome活动,说“司机取消了请求”

这可以做到吗?

CustomerCall

btnCancel = (Button)findViewById(R.id.btnDecline); 

btnCancel.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

cancelBooking();

}

});

}

private void cancelBooking() {

Intent intent = new Intent(getBaseContext(), RiderHome.class);

String cancel = "cancel"

intent.putExtra("cancel", cancel);

startActivity(intent);

Toast.makeText(CustomerCall.this, "The Driver has cancelled

the request", Toast.LENGTH_LONG).show();

}

RiderHome

public class RiderHome extends AppCompatActivity 

implements NavigationView.OnNavigationItemSelectedListener, OnMapReadyCallback,

GoogleApiClient.ConnectionCallbacks,

GoogleApiClient.OnConnectionFailedListener,

LocationListener {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_home);

}

}

回答:

你可以做到这一点way-:

private void cancelBooking() { 

Intent intent = new Intent(getBaseContext(), RiderHome.class);

String cancel = "cancel"

intent.putExtra("user_cancelled",cancel);

startActivity(intent);

Toast.makeText(CustomerCall.this, "The Driver has cancelled

the request", Toast.LENGTH_LONG).show();

}

在此传递一个字符串值,指示驾驶员取消请求

和RiderHome活动,你可以,如果你检查正在通过以下方式获取该值:

Intent intent=getIntent(); 

intent.getExtras();

if(intent.hasExtra("user_cancelled"))

{

You can print your toast here.

}

回答:

,而不是(烤面包与活动 - 吐司的生命是死的,当活动结束)

Toast.makeText(CustomerCall.this, "The Driver has cancelled 

the request", Toast.LENGTH_LONG).show();

到(使用背景!它会生存)

Toast.makeText(getBaseContext(), "The Driver has cancelled 

the request", Toast.LENGTH_LONG).show();

以上是 android - 将烤面包从一项活动传递给另一项活动 的全部内容, 来源链接: utcz.com/qa/260499.html

回到顶部