-1

I have location obtained in one activity.Now I want to store it somewhere so that I can use it later in another activity.How can I do that ? Is there any way of doing this android ?

dark_shadow
  • 3,503
  • 11
  • 56
  • 81
  • 1
    [Data Storage](http://developer.android.com/guide/topics/data/data-storage.html) - and -1 for no research effort. This is really easy to find. –  Nov 01 '11 at 21:05
  • @alextsc : "-1 for no research effort" Do I have to give the links of web sites which I have visited before asking this question ? – dark_shadow Nov 01 '11 at 21:25
  • Not neccessary links, but it should be visible that you have tried to find an answer to your question *(e.g. i found out that i could use X, but that didn't work because of error Y. I'm not sure if i can use Z [..])*. It's just bad to ask the same, well documented questions all over again. People get tired of it and stop giving answers *"because its the same !§$& every day"*. Which will in the end damage you, the one who needs an answer to a real question some day. It's also polite because people use their most limited resource "time" to help you. Don't waste it unneccesary. –  Nov 01 '11 at 21:37
  • @alextsc : Thanks for the advice.I'll try to show my efforts before asking any question ? – dark_shadow Nov 01 '11 at 22:17

3 Answers3

1

As said in the comments, you should take a look in the android docs here: http://developer.android.com/guide/topics/data/data-storage.html

If you want to use this data immediately in another activity then you could pass the data via an intent to the other activity. An example of this is here: How to pass an object from one activity to another on Android

With regard to data storage, SQLLite databases may be hard for a beginner, so in this instance, I would probably reccomend you use 'shared preferences' as they are easier to work with.

Community
  • 1
  • 1
Todd Davies
  • 5,484
  • 8
  • 47
  • 71
  • 1
    If I use to pass data from one activity to another it is much easier but the problem is startActivity(i) will automatically launch next activity.I want user to decide when to switch to other activity,is there any solution to this problem if I implement the shared preference ? – dark_shadow Nov 01 '11 at 21:23
  • 1
    You could store the location in a variable ( e.g. int location) or in the shared preferences. Then, when you wish to start the next activity, just pass the location to the next activity using a bundle from either the location variable or get it from the shared preferences. – Todd Davies Nov 01 '11 at 21:31
0

you can use the SQLite database to store the data, but you have to implement the DbHelper class in order to do so.

Another approach would be storing the data in the Application class, in a field or something, but I wouldn't recommend it because it would be messy, but that's my opinion; this approach is a lot more easy and fast to implement.

Alvin Baena
  • 903
  • 1
  • 10
  • 24
0

There are two simple ways to achieve this , either use sharedpreference or use bundle

Prachur
  • 1,100
  • 7
  • 24
  • 42
  • If I use to pass data from one activity to another it is much easier but the problem is startActivity(i) will automatically launch next activity.I want user to decide when to switch to other activity,is there any solution to this problem if I implement the shared preference ? – dark_shadow Nov 01 '11 at 21:26
  • "I want user to decide when to switch to other activity"(i did not understood this part). U can save any data using sharedpreference in any activity and retrieve the data from other activity. – Prachur Nov 01 '11 at 21:37