2017-12-18 163 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(); 
相關問題