Welcome Android Developpers

Welcome Android Developpers
My name is Mathias Séguy, I am an Android Expert and Trainer and created the Android2EE company.

For full information, it’s here : Android2EE's Training
You can meet me on Google+, follow me on Twitter or on LinkedIn

Saturday, December 24, 2011

Merry Christmas




Merry christmas to you.
May Santa's spirit be with you :o)

Saturday, December 17, 2011

Handler and activity's lifecycle available tutorials

Bandeau Conference
Hello,
You can find on Android2ee 3 tutorials that show you:

  • How to use Handler and manage its life cycle using AtomicBooleans
  • How to use Handler and manage its life cycle using onRetainNonConfigurationInstance method
  • A demonstration of the memory leak associated to the non management of the Handler life cycle.
Those Eclipse projects are downlaodable here : Hanlder Tutorials


So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
Android Trainings for Enterprise
AndroidEvolution
Retrouvez moi sur Google+
Suivez moi sur Twitter
Rejoignez mon réseau LinkedIn ou Viadeo

Thursday, December 15, 2011

Handler And LifeCycle Part III

Bandeau Conference

Hello again,
To continue with the issue of Handler and activity's life cycle, there is a solution, advocated by some, that is to use the public method Object onRetainNonConfigurationInstance () to return a pointer to an object in the activity.
Uh, let me explain, when your activity is to be destroyed and immediately recreates the method onRetainNonConfigurationInstance can send an object from the instance of the dying activity to the instance of new activity.
Example adapted to our problem:


@Override
public Object onRetainNonConfigurationInstance() {
                //Save the thread
                return backgroundThread;
}

to retrieve the object in the onCreate method:

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
//Do something
                backgroundThread = (Thread) getLastNonConfigurationInstance();
//Do something again
}


It is clear that with this method everything seems solved (at least for the change in orientation of the device). And yes, BUT NOT!!!, it's a serious mistake to think that. Indeed, what happens if your activity is killed (without being recreated immediately)? Well, then your thread is an orphan, your handler and your activity become ghosts (because the garbage collector detects them as used). And here, again, Darth Vader mocks.

The solution, and yes, there is one, is somewhat more complex than that. We must re-implement an atomic boolean to kill the thread if your activity is not restarted immediately.

And then, well, I invite you to get the tutorials that I dropped on Android2EE section Example/Tutorials/Handler's Tutorials. I give you 3 tutorials, one with the Atomic booleans, one with the onRetainNonConfigurationInstance instance and the last is a demonstration of the memory leaks.

But if your want the code, here it is:

Handlers, Threads and Activity's life cycle

Bandeau Conference
Hello,
As I said earlier, when managing Handlers or AsynchTasks, you must always make sure to link the life cycle of the thread with the Handler's one which is also linked with the activity's one ... Otherwise, your thread becomes an orphan Thread.
Ok, digging a little bit more (I will drop you on Androi2EE an eclipse project that shows what I'm saying) it's worse, in fact: When passing by OnDestroy and onCreate (short I return the device), not only the thread becomes orphan, but also the Handler (arg, what it is not destroyed o_O ') and worse is that your activity becomes a ghost ... glooops.
And yes it's crazy, the first activity is not destroyed, she is called by the first thread through the first Handler (hence the absence of the raise of a NullPointer exception) and the second activity is created with the new Handler and its new Thread.

I mean, DarkVador, Voldemor and Sauron laughed thinking of the number of threads, Handlers, AsynchTask, and activities ghosts that inhabit the Android devices because developers unaware of the danger.

So: Manage your threads by linking their life cycle with that of the activity.
So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution
Retrouvez moi sur Google+
Suivez moi sur Twitter
Rejoignez mon réseau LinkedIn ou Viadeo

Friday, November 25, 2011

Free Android Icons

Bandeau Conference
Hello,

As developpers, we always look for free icons, some are in the SDK but sometimes it's not enough.
You can find thousand of free icons on icones.pro (of course a lot of them are for a non commercial use, but you can contact the author to ask them).
If you have others sources of free icons, drop a comment.

So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution
Retrouvez moi sur Google+
Suivez moi sur Twitter
Rejoignez mon réseau LinkedIn ou Viadeo

Monday, November 21, 2011

Spinner, Managing size and text


Bandeau Conference

Hello,
Sometimes, when using a spinner, you want to manage its size and the font of the displayed text.
To do that you need to do 3 actions (I do that change on the Android spinner example : http://developer.android.com/guide/tutorials/views/hello-spinner.html
1.      Create a spinnertext.xml in your layout folder and define how the spinner’s title has to be displayed
2.      Change your spinner size in your main.xml (where your spinner is defined)
3.      Change your spinner declaration in your activity

Handler and Activity's life cycle, take care about orphan threads!!


Bandeau Conference
Hello,
You have an Activity which uses a Handler. You create your handler and overwrite the handleMessage method, you launch the handler’s thread and that’s it for the handler management… Most of us do such a thing and it’s a huge mistake!!! What happens to your thread when your activity pauses and resumes and worst when it dies and (re)creates? 
You thread becomes an orphan thread !

So you have written something like that :

Thursday, November 17, 2011

My Sensors (new Tutorial on Android2ee)

Bandeau Conference

Hello,
A new tutorial is available on Android2ee. I give you the ability to list the sensors available on the device. Quite simple.
The tutorial is here:
Tutos Android2EE and is called MySensors.
(All tutorials on this page are not available but RSSReader, DynamicGui and MySensors are).

In preparation some articles on sensors (and so some tutorials), see you soon.
So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution
Retrouvez moi sur Google+
Suivez moi sur Twitter
Rejoignez mon réseau LinkedIn ou Viadeo

Wednesday, November 16, 2011

How to disable sleep mode ?o?

Bandeau Conference
Hello,
It's quite easy,
You should use the PowerManager object to retrieve PowerService, then get the PowerManager.WakeLock object and ask for it. So in your Activity class declare the following attribute:

Tuesday, November 15, 2011

Android push methods




Bandeau Conference
Hello,


Sometimes it is very useful for our applications to be notified from our server (well of your server for your applications). This method is called the push and can send notifications to your application.
There are several "sioux" tricks there (via SMS, with a permanent connection to your http server ...). But the problem of "sioux" tricks is that they are not relevant when a turnkey solution is provided by the Android SDK itself. (In french a "sioux" trick is a ultimate trick, an indian trick, don't know the right translation).
In fact, Google makes available to developers servers designed for push and implementing commands that enable you to implement it in your application. This service Android Cloud to Device Messaging Framework also known as the C2DM allows you to implement this feature. Like many of Google features, you must register to enjoy.
The Google tutorial (still very bright) enables you in a "jiffy and two shots ladles" to implement this service:



http://code.google.com/intl/fr/android/c2dm/index.html
And a good push to you: o)


So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution
Retrouvez moi sur Google+
Suivez moi sur Twitter
Rejoignez mon réseau LinkedIn ou Viadeo

Initialize your application when first launched on the device.




Bandeau Conference
Hello,

Today I submit a simple way to implement actions at the first launch of your application on a phone. In other words, how to customize the first launch of your application?

The idea is quite simple and relies on the use of the object SharedPreferences. This object is used to store a set of key-value specific to your application within the system and be able to CRUD (create, read, update, delete) them easily.
The idea is to use this HashMap to retrieve ​​specific values of your application. In particular I would call a Boolean Initialized that lets you know if your application has already been launched on the Android device. The following code shows how to do (this code is in a class that extends Activity in the onCreate method):

How to send an Email O_o'


Bandeau Conference
Hello,
To send an email, just use the code below:

//load string for email:

String[] adresses=getResources().getStringArray(R.string.mail_adresses);
String subject=getResources().getString(R.string.mail_subject);
String body=getResources().getString(R.string.mail_body);

// send an email
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, adresses);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Notice that you are using Intent to call the Emails' sender activity.

So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution

Emulator screen capture ???



Bandeau Conference
Hello,

Just for those who wonder "how can i make a screen capture of my emulator's screen?", have a look in the DDMS view of Eclipse, there is a small button designed for that. It's the small camera in the tab paned that contains "Devices" and "Emultaor Controls" tabs. Yes, just there, on the right of those buttons, there are several buttons (Debug and so on) and the last button is the "Screen Capture" button.

So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution

Retrouvez moi sur Google+
Suivez moi sur Twitter
Rejoignez mon réseau LinkedIn ou Viadeo

How to manage screen brightness for your Activity?



Bandeau Conference
Hello,

There are several notions to understand when trying to change screen brightness.

First: You want to change your Activity's brightness

A simple place to find Android icons set.


Bandeau Conference
Hello,
A simple question that freezes us sometimes : Where can I find free Android icons for my applications...?
Just have a look in your Android SDK, there is a bunch of free android icons. You can find them under:
\android-sdk_r08-windows\android-sdk-windows\platforms\android-10\data\res\
There are sorted by density and locales, that will save yours GUI sometimes.
So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution

Android War Patents


Bandeau Conference
Hello,

As you all know, the war has just begun !!!

Have a look here (for a deeper comprehension of the war):
pcworld: mobile_patent_wars_a_closer_look_at_how_everyone_loses
and there :
smh.com.au: apple-v-samsung-war-might-have-been-avoided
Or there for older posts:
Par techCrunch
Par Htc-Dev
Par TalkAndroid
Par Larry Page (le CEO de Google, la source)

So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution

Android Evolution Infography

Bandeau Conference
Hello,

Just two infographies I like that describe the Android evolution:
fontera.com: Android-InfoGraphic
technobuffalo: android-infographic

So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution

Monday, November 14, 2011

Where are my Android logs ? in your DDMS ;o)


Bandeau Conference
Hello,

Noting that I took a very long time to find my logs Android, I told myself that I was not the only one. And indeed, in dev room, I was not alone.

So where are the logs and how to implement them?

Define your picture in dp not in px


Bandeau Conference

When defining an image (here, for example, use an image 73 pixels wide and 29 pixels high), you tend to write:

Define your pictures for all densities : ldpi,mdpi,hdpi (and xhdpi if you target tablet)



Bandeau Conference

In my previous post we understood why we need to declare our images in the layout file in dp (density-independent pixels). Thus, whatever the density of the screen, the image is the "same" size.
The corollary is: if you define/declare your pictures (in the folder drawable) once regardless of the density, they'll appear coarse in hdpi (and also in ldpi).

Welcome


Bandeau Conference
Welcome on my brand new blog.
For this new day, i will post some french posts here (i translate them first).
But before, who am I?
I am a french guy, expert in Java - J2EE (8 years of experience) and last year i decide to have a deep look at Android. So, i wrote three EBooks on it, I gave conferences in universities and engineering schools. And this year I will do training for Enterprise. So if you are intersted, just send me an email.
I have 3-5 days training session for enterprise, i'll drop soon an english version of the planing.

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks pour apprendre la programmation sous Android.
AndroidEvolution