[英]Pass JsonResponse to IntentService
我有My MainActivity
,可以得到很好的響應:
JSONObject responseVal = responseObj.getJSONObject("data");
message = responseVal.getString("id");
Log.i(TAG, "onResponse: " + message);
並且我有IntentService
並希望將該message
值傳遞給它。
我嘗試使用SharedPreferences
以及intentPutExtra
但是它不起作用。
最好的方法是什么?
如果要將該消息存儲到應用程序中,而不是用戶共享putextra
,則可以使用putextra
和getIntent.getextra()
方法。
點擊事件
Intent i=new Intent(this,yourclass.class);
i.putExtra("demo",message);
在yourclass.class
String mes=getIntent().getStringExtra("demo");
IntentService
message
發送到您的IntentService
,請嘗試以下操作:
Intent intent = new Intent(MainActivity.this, YourIntentService.class); intent.putExtra("message", message); startService(intent);
要在IntentService
接收message
,請嘗試以下操作:
@Override protected void onHandleIntent(Intent intent) { String message = intent.getStringExtra("message"); ........ }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.