Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8914573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:45:25+00:00 2026-06-15T04:45:25+00:00

Activity_A: Intent intent = new Intent(Activity_A.this, Activity_B.class); intent.putExtra(user_lat, getSharedPreferences( Activity_C.USER_PREFS, 0).getFloat( lat, 0)); Log.d(lat

  • 0

Activity_A:

Intent intent = new Intent(Activity_A.this,
                            Activity_B.class);
intent.putExtra("user_lat",
                    getSharedPreferences(
                    Activity_C.USER_PREFS, 0).getFloat(
                    "lat", 0));
Log.d("lat from prefs = ",
            getSharedPreferences(Activity_C.USER_PREFS, 0)
            .getFloat("lat", 0));
intent.putExtra("lng",
                    getSharedPreferences(
                    Activity_C.USER_PREFS, 0).getFloat(
                    "user_lng", 0));
Log.d("lng from prefs = ",
            getSharedPreferences(Activity_C.USER_PREFS, 0)
            .getFloat("lng", 0)");

The Logcat shows:

12-01 12:36:53.409: D/lat from prefs =(554): 18.599348

12-01 12:36:53.409: D/lng from prefs =(554): 73.7625

and Activity_B:

    try {

        MyLat = this.getIntent().getDoubleExtra("user_lat", 0);
        MyLng = this.getIntent().getDoubleExtra("user_lng", 0);
    } catch (Exception e) {

        Log.e("Exception in getting user lat and lng as Double",
                e.toString());
    }
    if (MyLat == 0.0 || MyLng == 0.0) {

        try {

            MyLat = this.getIntent().getFloatExtra("user_lat", 0);
            MyLng = this.getIntent().getFloatExtra("user_lng", 0);
        } catch (Exception e) {

            Log.e("Exception in getting user lat and lng as Float",
                    e.toString());
        }
    }

    Log.d("MyLat and MyLng", MyLat + "+" + MyLng);

and LogCat:

12-01 12:36:57.168: D/MyLat and MyLng(554): 18.599348068237305+0.0

and the LogCat error:

12-01 12:36:57.138: W/Bundle(554): Key user_lat expected Double but value was a java.lang.Float.  The default value 0.0 was returned.
12-01 12:36:57.159: W/Bundle(554): Attempt to cast generated internal exception:
12-01 12:36:57.159: W/Bundle(554): java.lang.ClassCastException: java.lang.Float
12-01 12:36:57.159: W/Bundle(554):  at android.os.Bundle.getDouble(Bundle.java:1017)
12-01 12:36:57.159: W/Bundle(554):  at android.content.Intent.getDoubleExtra(Intent.java:3377)
12-01 12:36:57.159: W/Bundle(554):  at com.wicfy.mobileapp.MapMarkerActivity.onCreate(MapMarkerActivity.java:60)
12-01 12:36:57.159: W/Bundle(554):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-01 12:36:57.159: W/Bundle(554):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-01 12:36:57.159: W/Bundle(554):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-01 12:36:57.159: W/Bundle(554):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-01 12:36:57.159: W/Bundle(554):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-01 12:36:57.159: W/Bundle(554):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-01 12:36:57.159: W/Bundle(554):  at android.os.Looper.loop(Looper.java:130)
12-01 12:36:57.159: W/Bundle(554):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-01 12:36:57.159: W/Bundle(554):  at java.lang.reflect.Method.invokeNative(Native Method)
12-01 12:36:57.159: W/Bundle(554):  at java.lang.reflect.Method.invoke(Method.java:507)
12-01 12:36:57.159: W/Bundle(554):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-01 12:36:57.159: W/Bundle(554):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-01 12:36:57.159: W/Bundle(554):  at dalvik.system.NativeStart.main(Native Method)

I thought, since i am taking user_lat as a double in Activity_B, i must cast it to double during intent.putExtra

but then i get this in LogCat:

12-01 12:36:57.168: D/MyLat and MyLng(554): 0.0+0.0

12-01 12:07:50.218: W/Bundle(498): Key user_lat expected Float but value was a java.lang.Double.  The default value 0.0 was returned.
12-01 12:07:50.249: W/Bundle(498): Attempt to cast generated internal exception:
12-01 12:07:50.249: W/Bundle(498): java.lang.ClassCastException: java.lang.Double
12-01 12:07:50.249: W/Bundle(498):  at android.os.Bundle.getFloat(Bundle.java:984)
12-01 12:07:50.249: W/Bundle(498):  at android.content.Intent.getFloatExtra(Intent.java:3360)
12-01 12:07:50.249: W/Bundle(498):  at com.wicfy.mobileapp.MapMarkerActivity.onCreate(MapMarkerActivity.java:71)
12-01 12:07:50.249: W/Bundle(498):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-01 12:07:50.249: W/Bundle(498):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-01 12:07:50.249: W/Bundle(498):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-01 12:07:50.249: W/Bundle(498):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-01 12:07:50.249: W/Bundle(498):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-01 12:07:50.249: W/Bundle(498):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-01 12:07:50.249: W/Bundle(498):  at android.os.Looper.loop(Looper.java:130)
12-01 12:07:50.249: W/Bundle(498):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-01 12:07:50.249: W/Bundle(498):  at java.lang.reflect.Method.invokeNative(Native Method)
12-01 12:07:50.249: W/Bundle(498):  at java.lang.reflect.Method.invoke(Method.java:507)
12-01 12:07:50.249: W/Bundle(498):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-01 12:07:50.249: W/Bundle(498):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-01 12:07:50.249: W/Bundle(498):  at dalvik.system.NativeStart.main(Native Method)

I get none of the Log.e message. May be because its an Internal Exception and doesn’t cause a crash.

So, how can i get the actual values which i am sending throught intent from Activity_A in Activity_B

Thank You

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:45:26+00:00Added an answer on June 15, 2026 at 4:45 am

    Since the value is already stored in a SharedPreferences file, it seems the simplest answer is to not use the Intent.

    In Activity B use:

    float myLat = getSharedPreferences(Activity_C.USER_PREFS, 0).getFloat("lat", 0);
    // Read the Longitude in the same way
    

    You are trying to work with Doubles from a Location object (I assume) however SharedPreferences don’t work with Doubles. You might be safer converting the Doubles to Strings and back. This way you don’t gain or lose any precision going to and from Floats.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I launch an activity to capture a picture from camera: Intent i = new
How do I pass an intent from an activity to a class extending surfaceview?
I have a Class A which runs activity via startActivityForResult by passing Intent to
In my app I send some intent extras from one activity to another. But
I am trying to send data through intent from one activity to another. But
Activity_A calls Activity_B (startActivity() and when _B calls finish(); both activities close. I'm adding
EDIT I now have this code: public void sendMessage(View view) { Intent intent =
I get the below error in the line this.viewcam.setOnClickListerner(new view.OnClickListerner()) . I get this
How do I pass a value from one class to another. eg Class one
I've got Activity A which fires up the Camera intent via: Intent intent =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.