0

hi i hope someone can help i am new to developing, i have managed to get this app i am building running previously on a windows machine and i am redevloping for android. the scenario is this. I need a user to input data, i can get this into shared prefences which is ok. But i need this to be a 1 time operation, the data is an id number. first time the application is run the user enters their Id number, the application uses this id number as part of an email which is sent. The next time the user runs the app i dont want the app asking them to enter their id again.

I got this working on a windows based machine by writing the data out to a file, when the app started it would check if file existed, if file existed then it would open the relevant form for email, if the file didn't exist it would open the data input form.

I hope i have explained the issue clearly enough. all help appreciated thanks.

  • possible duplicate of [How to use SharedPreferences in Android to store, fetch and edit values](http://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values) – David Snabel-Caunt Mar 22 '12 at 17:09
  • You might consider adding just a tad more info (brief naturally) to the title. And use the search function too. Give it a try and you will find it mighty useful. ;-) – Siddharth Lele Mar 22 '12 at 17:11
  • still not sure what your question is since you "got this working". – Dhruv Gairola Mar 22 '12 at 17:27

3 Answers3

1

What you are looking for is persistent storage in android. There are four ways to store the ID of the user

  1. Shared Preferences
  2. Internal Storage
  3. External Storage
  4. SQLite Database
  5. Network Connection

Since you have mentioned that you have already done this on windows by storing it on file you can do the same here with external storage method .

You can find more about these here

pshirishreddy
  • 746
  • 6
  • 20
0

Use internal storage:

String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

Sully
  • 14,672
  • 5
  • 54
  • 79
  • SharedPreferences are a simpler approach. – David Snabel-Caunt Mar 22 '12 at 17:20
  • when i say i "got this to work", it was in relation to a windows application i wrote using visual basic. I am now looking at writing the same application but for android which i am having to get my head around java language. – vindimat Mar 22 '12 at 23:18
  • The way i got it to work on windows was to write the data the user inputed into a file. The data in the file was then read and combined with data from a different file, which then became the subject on an email. text file number one contained the users ID number, text file number 2 contained preset data i.e "device tested". A streamreader then pulled the data from both files which produced " 51242425 device tested". when the application ran it checked if text file number one existed if not user enters id, if exists then it asks user device tested or not. – vindimat Mar 22 '12 at 23:40
0

I don't seem to understand the problem

            SharedPreferences sharedPreference= PreferenceManager.getDefaultSharedPreferences(this);
            SharedPreferences.Editor editor = sharedPreference.edit();
            editor.putString("KEY-REQUIRED", VALUE);
            editor.commit();

Well notice KEY-REQUIRED this is what you call when you want the data of VALUE.

This KEY-REQUIRED is completely rewritable you can overwrite it non-stop and the value can keep changing.

sdfwer
  • 1,042
  • 3
  • 10
  • 23