JSON exists everywhere and used mainly in REST APIs, There are many ways to read JSON files but here I will cover the two ways that are supported by Gson library.
- Object Model
- Stream Model
Operate on a JSON document as a sequence of tokens that are traversed in depth-first order. Because stream mode reads one token at a time it requires less memory. It is similar to Pull Parsers way to read XML files.
When to use each model depends on your needs, If your JSON file is small then using object model to load the whole file into memory at once will be best choice, But if your JSON file it too large then using stream model will be the best.
I was having a large JSON file (≈ 30 MB) that I wanted to read. I couldn’t read the whole file at once using object model because loading all this data into memory made the system crash, So here I will describe how to use GSON library to read this file using stream model.
Firstly, Let’s take a look how the JSON file formed
City and Coord model classes
Now we will read the JSON file from assets folder using stream model
With this approach we are loading objects one by one, and each time we convert the object that has been read to City model object.
- http://www.acuriousanimal.com/2015/10/23/reading-json-file-in-stream-mode-with-gson.html (This covers reading using object model and stream model)
I was reading about Android Intents and I found this explanation very simple.
An Intent is an “intention” to perform an action; in other words,
a messaging object you can use to request an action from another app component
An Intent is basically a message to say you did or want something to happen. Depending on the intent, apps or the OS might be listening for it and will react accordingly. Think of it as a blast email to a bunch of friends, in which you tell your friend John to do something, or to friends who can do X (“intent filters”), to do X. The other folks will ignore the email, but John (or friends who can do X) will react to it.
To listen for an broadcast intent (like the phone ringing, or an SMS is received), you implement a broadcast receiver, which will be passed the intent. To declare that you can handle another’s app intent like “take picture”, you declare an intent filter in your app’s manifest file.
If you want to fire off an intent to do something, like pop up the dialer, you fire off an intent saying you will.
Udacity has launched an Android Developer Path Guide. If you are newbie or have some experience with Android, take a look to that map to know the skills that you lack.
There are 3 levels in Udacity for Android developers:
He is a former child prodigy who entered college at the age of 12, finished his bachelor’s degree at 14 and his PhD at 20 years old.
Currently, Erik is 36 years old and is a computer science professor at MIT. You can find his lectures, books, papers and many more things on.
Two weeks ago I faced a problem, I was storing a pdf file in internal storage and I wanted to share it via another apps like Gmail, or any other sharing app. When I tried to attach it to Gmail for example I got this error “Permission denied for the attachment“.
The problem is that data saved in internal storage isn’t accessible by other applications.
After a while I figured it out, that the solution is in Content Providers.
Content Providers have a lot of uses one of them is providing a way to share data with other apps.
In manifest we declare the content provider :
name attribute is my custom content provider class, authorities attribute is URI that identify data offered by the content provider, exported is true means that the content provider is available for other applications to use.
After that we create our CustomContentProvider :
Finally, We will use our custom content provider to share our pdf file :
CONTENT_URI means I am going to use content provider “content://” + provider’s_authority + “/” + absolute file path.
That will allow our app to share the pdf file.
This chapter is all about making sure that your software works in a real-world context.
Analysis: is figuring out potential problems, and then solving those problems before you release your application
out into real world.
In this chapter he talk about some notes in Class Diagram let’s see it … 🙂
1) Delegation helps our applications stay loosely coupled.That means that your objects are independent
of each other.
4) Think about how the classes you do have can support the behavior your use case descripe.
5) Pay attention to the nouns in your use case, even when they aren’t classes in your system.
6) Write your use cases in a way that makes sense to you, your boss, and your customers.
Finally the source code for Modified Dog Door System that he talk about it in this chapter you can find it Here. I implement it in C#.