Android Internal Storage Tutorial: How to Cache Data for Offline (2016)

Android Internal Storage Tutorial: How to Cache Data for Offline (2016) - Hello friends Android tutorial and tips trik, The article you are reading this time with the title Android Internal Storage Tutorial: How to Cache Data for Offline (2016), we have prepared this article for you to read and download the information therein. hopefully fill posts article 2016, article android, article Cache, article data, article for, article How, article Internal, article Offline, article Storage, article TO, article Tutorial, we can write this you understand. Well, happy reading.

Title : Android Internal Storage Tutorial: How to Cache Data for Offline (2016)
link : Android Internal Storage Tutorial: How to Cache Data for Offline (2016)

Baca juga


Android Internal Storage Tutorial: How to Cache Data for Offline (2016)

Hello everyone! My name is Oum Saokosal.

Today I'm going to talk about how to cachedata in the internal storage in android.

Actually I created a library for you.

it's gonna be easy to do that and you cansolve a lot of problems like, you can cache JSON data from the internet and store in yourinternal storage and use while there is no internet.

You know like, that is offline then you canjust use the data and display the data offline.

So first I would like to introduce you tomy youtube channel.

So, this is my YouTube channel and subscribefor more video.

You can see a lot of materials, some in Englishand some in Khmer but make sure you find the English one and this is my GitHub.

Now, to use the File Cacher, which is thename of the library, you go to https://github.

Com/kosalgeek and you go to Repositories,you should find File Cacher and you can see the tutorial here.

So, first download it.

So, let's hit download.

Open it and unzip it.

So, you can see the same call Code here andthe library here or you just need the File Cacher, just copy and then you go to yourproject and this is my project.

And then you go to project here and you willfind apps and libs.

So, right click on the libs folder.

Then, paste it here.

Ok! Then, you right click on this and add thelibrary.

And you can go back to android and you cango to Gradle too.

Gradle files and the second one.

You should see the line here, Libs/FileCacher It means that you added correctly.

Now you go back to the project in Java file.

What you have to do is called the File cacherand if you don't know you can follow along the tutorial here.

So now you want to cache some string.

You need to add generic drive like this.

Make sure that when you read and write youget the correct type.

So, this is a string but is not limited tothe three and you can cast ArrayList of any class or maybe HashMap or maybe some text, youknow like, generic type.

That's all.

And then you can call String Cache and youcan write some data here and here you can say some text and you need to Cache the narrow, IOException because sometimes the Internal storage may be broken or maybe error, youknow.

So you can add your post here, you know that,there's something wrong.

So let's put it this way and then if you wantto read it, you can just call read Cacher and read it.

That's all.

So, there's another error exception but tomake sure that you read it correctly.

you have to check if the String Cacher hasCache.

So, some time you don't have this.

So, you might have some error.

Test something like this.

Ok! So for now, I want to return it to a string.

Because I want to use the law, so I just clickTAG here like this and here you can say TAG text.

So if it is working, then, you gonna see sometext you know in the block below.

You can see now you can see some text.

Ok! Let's say you delete it because imagine youare using offline, you know, internet.

As you can see you can still see the textit means that it can stay in your internal storage and it can work in another activityas well.

So, let create another activity.

Choose blank activity and a college sub activityand choose hierarchy here.

Now, in your sub activity, you can do thesame.

First, you create a file cache.

Then, you call File Cacher.

So it's context and the form name should bethe same time.

So, it's some text activity.

If we use the same file name like this, itmeans that the use the same cache, so be careful if you are using the same name but a differentthing.

You can conflict and it can cause your appto not responding.

Ok! So you had to make sure that this is the samecache that you want to use.

Now let's call read.

I don't have to check because I know but ifyou want to check it, you still can do the same.

Cache.

HasCache.

And surrounded by try-catch.

Ok! Let's call string, text again.

And in here you have to explicitly give the type Stringand then maybe you can do the same for here.

So, giving a TAG is easy.

And if you want to open some activity from here, so in the content made, I have a button then just useMain activity and this is even here so I just call Intent in = new Intent(MainACtivity.

This, SubActivity.

Class) And you start activity like this.

This should go to Sub activity when you clickon the button.

Run again.

As you can see the main activity is some text.

Now click on the button and call it Sub activity.

As you can see you can still see the sometext here.

It means that you can Cache in some app andyou can use another method for example, if you want to clear cache, you can do it.

I just called clear Cache.

It doesn't need any parameter here.

Call it.

Ok! On main activity, you can see that it's nocache here and if you go to Sub activity, there is no cache.

Ok! And one more thing that I really want to shareis that because you use the same file maybe you are confusing and you accidentally useit and it press a string and then in the Sub activity maybe you use like, ArrayList forexample, you do something like this it's the same file but a different TAG.

And Let's say, writeCache, some text Ok! You thought that okay, you get the same asthey are and because you don't know the type and you may accidentally use like this andyou will see something happen.

Ok! Now in the main, you see some text again herebut let's go to the sub activity.

As you can see now that is broken.

If you go to sub activity you will see thetext here and it says, ClassCastException.

Then it means that you cast to the wrong class.

So, I recommend you to cache another catchwhich is, ClassCastException.

You do like this and you might add your codehere.

Then the app will not be broken and you cansee the message here instead.

Ok! Let's go to the sub activity.

Now you can see the app not broken but yousee the message here.

So you can handle a message yourself.

Ok! Close the cache, see you know they said thatthe string cannot be casted.

So, just do it yourself.

And if you want to see the whole Cast, youcan call the file cast manager.

Ok! You can see that you call the code down below.

Just copy.

So what it does, is that you will get contextof your app and you can display your path.

You can change your files, maybe one or morefile exists or not.

And you can retrieve all the name of the filesand let's do the log here.

Let's run it.

Now you'll see that time of year so it isin there in your app and files folder and file name is some text dot txt if you havemore than one file, then you can see more files here and you can delete all the filesas well.

If you want to, you call manager and deleteall file like this but it will be gone, all of files will be gone.

So make sure that you want to delete all offile otherwise don't use it because this cache will be deleted while your application deletesit.

If you think it has a lot of cache, so youdo delete it yourself.

If not, just leave it there.

So that's all for the video.

So make sure that you subscribe my channeland I will see you in the next video.

Thank you!.



Thus Article Android Internal Storage Tutorial: How to Cache Data for Offline (2016)

That article Android Internal Storage Tutorial: How to Cache Data for Offline (2016) This time, hopefully we can give you all of the benefits. Well, I'll see you in another article post.

You now read the article Android Internal Storage Tutorial: How to Cache Data for Offline (2016) the link address http://svedda79.blogspot.com/2016/12/android-internal-storage-tutorial-how.html

0 Response to "Android Internal Storage Tutorial: How to Cache Data for Offline (2016)"

Post a Comment