簡體   English   中英

將JsonResponse傳遞給IntentService

[英]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 ,則可以使用putextragetIntent.getextra()方法。

點擊事件

Intent i=new Intent(this,yourclass.class);
i.putExtra("demo",message);

yourclass.class

String mes=getIntent().getStringExtra("demo");
  1. IntentService message發送到您的IntentService ,請嘗試以下操作:

     Intent intent = new Intent(MainActivity.this, YourIntentService.class); intent.putExtra("message", message); startService(intent); 
  2. 要在IntentService接收message ,請嘗試以下操作:

     @Override protected void onHandleIntent(Intent intent) { String message = intent.getStringExtra("message"); ........ } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM