Wednesday, June 10, 2015

C Array and pointer

int _tmain(int argc, _TCHAR* argv[])
{
int a[2][3] = { 0 };

printf("address of a = %p %p %p %p\n", a, &a, &a[0], &a[0][0]); // all equal a
printf("address of a + 1 = %p %p %p %p\n", a+1, &a+1, &a[0]+1, &a[0][0]+1); // a+3*4 ( 4 bytes per int), a+6*4, a+3*4,a+4

}

Saturday, May 30, 2015

passing data from intent

http://stackoverflow.com/questions/768969/passing-a-bundle-on-startactivity

1) Use the Bundle from the Intent:
Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);  
2) Create a new Bundle
Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putString(key, value);
mIntent.putExtras(mBundle);
3) Use the putExtra() shortcut method of the Intent
Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value);

implements Serializable

you can stream your Java object to a sequence of byte and restore these objects from this stream of bytes. 

http://www.vogella.com/tutorials/JavaSerialization/article.html

Wednesday, May 27, 2015

“implements Runnable” vs. “extends Thread”

http://stackoverflow.com/questions/541487/implements-runnable-vs-extends-thread

by extending Thread, each of your threads has a unique object associated with it, whereas implementing Runnable, many threads can share the same object instance.

Output of the above program.

ImplementsRunnable : Counter : 1
ImplementsRunnable : Counter : 2
ImplementsRunnable : Counter : 3
ExtendsThread : Counter : 1
ExtendsThread : Counter : 1
ExtendsThread : Counter : 1

Looper and thread

When I created a handler inside a thread ( not main thread ), the program will terminate directly.

According the logcat log, it needs Looper, after added the Looper inside the thread, it works.



Monday, May 25, 2015

Building a Notification with a pendingintent

http://developer.android.com/training/notify-user/build-notification.html

Remember to create your own notification icon in the drawable folder, otherwise you can't figure out whether the notification is showing up or not.