1

I have such a problem while sending intent with extras: values put as double are converted to integer, and cannot be read as double when receiving the intent. The code is below.

creation of the Intent in onUpdate method of WidgetProvider:

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);

Reception of the Intent in onReceive method of WidgetProvider:

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();
  }

This lines:

Double longitude = new Double(intent.getDoubleExtra(LONGITUDE, -100));
Double latitude = new Double(extras.getDouble(LATITUDE, -100));

throw warning in DDMS LogCat:

warning

What can cause this error?

Community
  • 1
  • 1
k4b
  • 185
  • 1
  • 2
  • 12
  • 1
    Verify the content of the extras in `onReceive()`. Either add debug code to dump the extras, or put a breakpoint there and have a look at them. I'm guessing that you aren't really sending the `Intent` that you think you are. – David Wasser May 29 '12 at 17:13

2 Answers2

0

To not get this warning you could use -100.0 instead because that is the Integer its complaining about. But that won't solve your problem.

Your Intent seems not to have a value for the key LONGITUDE.

Dirk Jäckel
  • 2,893
  • 3
  • 28
  • 47
0

here are some tips:

  1. don't use "new Double" . you can simply put the value alone . the compiler knows what to do with that . "new Double" is used if you wish to differ between variables instead of values .for example:

    Double x=10.0,y=x,z=new Double(x);
    

    so here , x==y , but x!=z .

    try to change it in all of your code and see if it helps.

  2. for "getDoubleExtra" , use 100.0 instead of 100 .

  3. for getting the values , you don't need to use Double . double is ok . you can also use null as the default value if you wish (in case you use Double) .

android developer
  • 106,412
  • 122
  • 641
  • 1,128