You should’ve asked

Emma

Here is the english version of my now famous “Fallait demander” ; soon to come as a book with other stories :

MentalLoad_cover.jpg

Preorders available here or here or here ^_^

Thanks Una from unadtranslation.com for the translation 🙂

You should've asked_001You should've asked_002You should've asked_003You should've asked_004You should've asked_005You should've asked_006You should've asked_007You should've asked_008You should've asked_009You should've asked_010You should've asked_011You should've asked_012You should've asked_013You should've asked_014You should've asked_016You should've asked_017You should've asked_018You should've asked_019You should've asked_020You should've asked_021You should've asked_022You should've asked_023You should've asked_024You should've asked_025You should've asked_026You should've asked_027You should've asked_028You should've asked_029You should've asked_030You should've asked_031You should've asked_032You should've asked_033You should've asked_034You should've asked_035You should've asked_036You should've asked_037You should've asked_038You should've asked_039You should've asked_040

View original post

Advertisements

Read Large JSON Files Using Gson

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

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

Load the whole file in memory and translate each JavaScript object to a Java object containing all the properties, array objects, etc. It is similar to the DOM way to read XML files.

  • 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

cities_json

City and Coord model classes

city_model

coord_model

Now we will read the JSON file from assets folder using stream model

read_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.


References

What Is Android Intent ?

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.


References

Android Developer Path

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:

  1. Beginner
    1. Android Basics: User Interface
    2. User Input
    3. Multi-Screen Apps
    4. Networking
    5. Data Storage
  2. Intermediate
    1. Developing Android Apps
  3. Advanced
    1. Advanced Android App Development

References

android-developer-path

Share Android App Internal Storage Data

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 :

manifest-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 :

custom-content-provider

Finally, We will use our custom content provider to share our pdf file :

sharing

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.

Chapter 4

In this chapter we talk about :-

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 … 🙂

Notes:-
1) Delegation helps our applications stay loosely coupled.That means that your objects are independent
of each other.


2) The nouns in a use case are usually the classes you need to write.
3) The verbs in your use case are usually the methods of the objects.


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.


7) Association: means that one class is associated with another class by refrence,extension,inheritance,…etc
8) There are some important key words:-

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#.