0

I want to send a double value data from one application to another. I have created 2 applications, the one application will send latitude and longitude (both double value) to another application on every 10 mins.I have used service for it. And second application will just get these values and it will show to user. Can you just give me a little example for passing the double value

Thank you

cryptic
  • 168
  • 1
  • 10

1 Answers1

1

I suggest you create a variable which contains all the information. Then use

Intent i = new Intent(getApplicationContext(), NewActivity.class);
i.putExtra("new_variable_name","value");
startActivity(i);

Then in the new Activity, retrieve those values:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("new_variable_name");
}

i found the answer here

EDIT : it also works with double doubleVal1 & 2 being your variables

Intent yourIntent = new Intent(thisActivity.this, nextActivity.class);
Bundle b = new Bundle();
b.putDouble("latitude", doubleVal1);
b.putDouble("longitude", doubleVal2);
yourIntent.putExtras(b);
startActivity(yourIntent);

Then, get it in your next Activity:

 Bundle b = getIntent().getExtras();
 double mLatitude = b.getDouble("latitude");
 double mLongitude =b.getDouble("longitude);"`

it cames from this question pass double values in intent

Community
  • 1
  • 1
PhValt
  • 11
  • 4
  • you can easily convert to String() - get the String, cut it, and recreate the double values. – PhValt Dec 05 '14 at 08:00
  • Don't copy-paste older answers, it's considered as a bad practice. Make a comment behind the question instead. – aga Dec 05 '14 at 08:06
  • You are right, sorry, my mistake .i was meaning the question had already been answered on the site : like here. http://stackoverflow.com/questions/9588026/passing-a-double-value-through-to-a-different-class-in-android-java also i can´t comment his question, not enough rep – PhValt Dec 05 '14 at 08:45
  • I want to pass the value from application to application...not from activity to activity..I tried your given solution @PhValt..But it failed....My code of passing values.. Intent i = new Intent(Intent.ACTION_MAIN); PackageManager manager= getPackageManager(); i=manager.getLaunchIntentForPackage("com.example.trackerdevice"); i.putExtra("Lat", latitude); i.putExtra("Long", longitude); i.putExtra("Mobile", "123456"); i.addCategory(Intent.CATEGORY_LAUNCHER); startActivity(i); – cryptic Dec 08 '14 at 13:19
  • The above code is not working...can you give some suggestions?.. Thank you – cryptic Dec 08 '14 at 13:22