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.

Sunday, May 24, 2015

Content provider is not thread safe.

http://www.androiddesignpatterns.com/2012/10/sqlite-contentprovider-thread-safety.html

Android Binder Note.

https://www.youtube.com/watch?v=Jgampt1DOak


Intents, Content Providers, Messenger, all system services like Telephone, Vibrator, Wifi, Battery, Notification, etc. utilize IPC infrastructure provider by Binder. Even the lifecycle callbacks in your Activity like onStart()onResume()onDestroy() are invoked by ActivityManagerServer via binders.
Proxies take your high-level Java/C++ method calls (requests) and convert them to Parcels (Marshalling) and submit the transaction to the Binder Kernel Driver and block. Stubs on the other hand (in the Service process) listens to the Binder Kernel Driver and unmarshalls Parcels upon receiving a callback, into rich data types/objects that the Service can understand.


Tuesday, May 19, 2015

Revert String

int _tmain(int argc, _TCHAR* argv[])
{
char mark[] = "I am Mark BB";
int len = sizeof(mark) / sizeof(char) - 1 ;

printf("length = %d\n", len);

for (int i = 0; i < len/2; i++)
{
char tmp = mark[len - i - 1 ];
mark[len - i - 1] = mark[i];
mark[i] = tmp;
}

for (int i = 0; i <= len; i++)
printf("mark[%d] = %c\n", i,mark[i]);
}

Content Provider Introduction.

Content provider provides a generic interface for accessing data with IPC functionality.
http://developer.android.com/guide/topics/providers/content-providers.html

http://blog.changyy.org/2012/05/android-app-content-provider.html

http://examples.javacodegeeks.com/android/core/content/contentprovider/android-content-provider-example/