android - 从一个 activity 向另一个 activity 敬酒
android - pass a toast from one activity to another activity
不确定这是否有效,但我正在尝试从 CustomerCall activity.
向 RiderHome activity 发送消息
一旦 driver 选择取消。需要向 RiderHome activity 说 "The Driver has cancelled the request"
这可以做到吗?
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();
}
骑士之家
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);
}
}
而不是(用 activity 吐司 - 当 activity 完成时 Toast 的生命就死了)
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();
你可以这样做-:
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 Activity 中,您可以通过以下方式检查您是否获得了该值:
Intent intent=getIntent();
intent.getExtras();
if(intent.hasExtra("user_cancelled"))
{
You can print your toast here.
}
不确定这是否有效,但我正在尝试从 CustomerCall activity.
向 RiderHome activity 发送消息一旦 driver 选择取消。需要向 RiderHome activity 说 "The Driver has cancelled the request"
这可以做到吗?
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();
}
骑士之家
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);
}
}
而不是(用 activity 吐司 - 当 activity 完成时 Toast 的生命就死了)
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();
你可以这样做-:
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 Activity 中,您可以通过以下方式检查您是否获得了该值:
Intent intent=getIntent();
intent.getExtras();
if(intent.hasExtra("user_cancelled"))
{
You can print your toast here.
}