我有這樣的問題,同時發送額外的意圖:值放置爲double被轉換爲整數,並且不能在接收意圖時讀爲double。代碼如下。Android意圖額外值鑄造錯誤:雙重鑄造到整數
創作WidgetProvider的的onUpdate方法的意向:
Intent send = new Intent("ACTION_SEND_DATA");
send.putExtra("url", "http://some-url.com");
send.putExtra(LONGITUDE, new Double(13.65));
send.putExtra(LATITUDE, new Double(43.12));
PendingIntent sendPendingIntent = PendingIntent.getBroadcast(context, 0, send, 0);
views.setOnClickPendingIntent(R.id.Change, sendPendingIntent);
招待會WidgetProvider的的onReceive方法的意向:
else if (intent.getAction().equals("ACTION_SEND_DATA"))
{
Log.d("WIDGET", "received ACTION_SEND_DATA intent");
String msg = intent.getStringExtra("url");
Bundle extras = intent.getExtras();
if (extras != null)
{
// Get data via the key
String url = extras.getString("url");
Double longitude = new Double(intent.getDoubleExtra(LONGITUDE, -100));
Double latitude = new Double(extras.getDouble(LATITUDE, -100));
msg = "received: " + url + " " + longitude + " " + latitude;
sendData(extras);
}
else
msg += " no extras!";
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
}
這行:
Double longitude = new Double(intent.getDoubleExtra(LONGITUDE, -100));
Double latitude = new Double(extras.getDouble(LATITUDE, -100));
擲警告在DDMS LogCat中:
warning http://i47.tinypic.com/24kwk8h.png
什麼會導致此錯誤?
驗證'onReceive()'中附加項的內容。可以添加調試代碼來轉儲額外功能,也可以在其中放置斷點並查看它們。我猜你並不是真的在發送你認爲你是的「意圖」。 –