Reputation: 904
My app uses Google Places and Directions API. I see a nullpointerException in my app.
Activity1:
< AutoComplete TextView 1 > // Uses Places API
< AutoComplete TextView 2 > // Uses Places API
< Button > // Uses Directions API, and proceeds to Activity2
Activity2:
< List > // List of search results
1) User has to select the places from the AutoComplete dropdown list in Activity1. This fetches the latitude and longitude values for the two selected places. 2) User now presses the button in Activity1. It uses Directions API to calculate the distance and proceeds to Activity2.
From Activity2, user presses the back key, and comes back to Activity1. The two AutoComplete TextViews would already have places filled up. When user presses the button, there in no value for latitude and longitude values, and this is causing the exception.
Please suggest an approach that helps me retain the latitude and longitude values when Activity1 is entered from Activity2.
Upvotes: 0
Views: 53
Reputation: 1268
You should store your values in onSavedInstanceState(Bundle bundle) and get back the values from the bundle you can find in the onCreate method.
Check out this link: http://developer.android.com/training/basics/activity-lifecycle/recreating.html#SaveState
Upvotes: 1
Reputation: 21
To retain value you need to use a method to save your data.
Check:
http://developer.android.com/training/basics/data-storage/index.html
Upvotes: 0