Slick Forums

Discuss the Slick 2D Library
It is currently Sat Feb 23, 2019 12:13 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: saving files
PostPosted: Sat Apr 21, 2012 9:07 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
so i'm very new on android,
where and how can i save and load my persist files?

tx


Top
 Profile  
 
 Post subject: Re: saving files
PostPosted: Mon Apr 23, 2012 6:15 pm 
Offline

Joined: Tue May 03, 2011 10:38 pm
Posts: 32
You can follow this guide here, and Slick actually has a built in way of saving through Muffin, however I don't have experience with Muffin and I used my own way to save files.

The idea is to create your file, be it with an XML parser or otherwise, and create the file there. What I had to do was have two sections of code, one for saving on desktop and the other for Android devices, and comment out the section I wasn't using. For saving you can use a File object and choose the path.

For desktop, you can give it any path from the root, and it would look like:

Code:
File fExample = new File("/Android/data/package.name/" + filename);


And for Android, you should be saving it to the SD card under /Android/data/package.name, but to get to that you need to use an Environment variable like so:

Code:
File fExample = new File((Environment.getExternalSttorageDirectory() + "/Android/data/package.name/" + filename);


After that you can create your file and save it like you would for any other Java program. To open the file you created, you can access it the same way as you created the file.

Creating your files in the proper structure will allow for those files to be removed from the device when the user uninstalls your application.

Under your Android project, you also need to add this line to your AndroidManifest.xml:

Code:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


Hope this helps.


Top
 Profile  
 
 Post subject: Re: saving files
PostPosted: Tue Apr 24, 2012 7:23 am 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
wow what a great exp ! tx ! i'll try it !


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group