Reputation: 3852
I am writing results from one activity to a file in my android emulator but, i am not able to read the same file in other activities.Actually i want to display the contents of the file in another activity in the edittext box.What I have to do to write the file to memory card and read the same in any other activity ?
Upvotes: 0
Views: 494
Reputation: 10948
Check out the accepted answer to this question. You won't have any problem reading something that was written in another Activity. Make sure you have the correct permissions as shown in Permission to write to the SD card.
Upvotes: 2
Reputation: 36289
Android also has some built-in functionality for storing data between activities. For example, you can create a SharedPreferences object and store this output as a String, with key value output (SharedPreferences uses a Map, where object is a simple type, such as String, int, boolean, etc. Using mode_world_writeable to define how you share between activities will let you retrieve this sharedPreferences mapping amongst any activities in your package.
String fileOutput //output from the activity to share as String.
SharedPreferences user_settings;
SharedPreferences.Editor user_settings_editor;
user_settings = getSharedPreferences(getResources().getString(R.string.user_prefs_file), Context.MODE_WORLD_WRITEABLE);
user_settings_editor = user_settings.edit();
user_settings_editor.putString("output", fileOutput);
user_settings_editor.commit();
Upvotes: 2