2017-12-18 164 views
0

不确定这是否有效,但我正尝试从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); 

    } 

} 
+0

如何浏览RiderHome活动?你可以使用intent包含你的代码片段吗? –

+0

为什么不只是在CustomerCall活动上敬酒?如果你只是要烤面包,你为什么还需要将其他活动的吐司/消息传递给另一个活动? –

+0

@ TentenPonce驱动程序取消请求后,需要将msg发送给骑手,请求被取消 – LizG

回答

1

你可以做到这一点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. 

} 
+0

感谢您的输入,但没有工作:/。它与不同用户的应用程序,所以也许这就是为什么它不工作。我想如果我只是传递一个字符串,如果字符串通过,我可以然后打印吐司。没有运气, – LizG

+0

你能转移到骑手活动吗? –

+0

从CustomerCall活动到意图? – LizG

-1

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

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(); 
相关问题