Tuesday, June 14, 2011

Launching third party application through Intent

The snippet for launching a third party application through intent is,


Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.smartandroidians", "com.smartandroidians.NotificationWithAction");
startActivity(intent);


The first parameter in setClassName() is the package name and the second parameter is the launcher activity class name

Friday, June 3, 2011

Cursor management in Honeycomb

If you are targeting your application for honeycomb, then some APIs related to cursor management are deprecated and your application won't work smoothly in honeycomb, eventhough it will work well in other versions of Android. In Honeycomb, cursor management is more tightly coupled and Some of the APIs that are deprecated are

- startManagingCursor()
- stopManagingCursor()
- managedQuery()
- reQuery()

If you are using any of these methods in HoneyComb, then you will get an exception, like

java.lang.IllegalStateException: trying to requery an already closed cursor

If you are using managedQuery() in lower versions of Android(2.3,2.2) as,

cursor = context.managedQuery(android.provider.Browser.BOOKMARKS_URI, projection, null, null,
null);

then in Honeycomb you need to modify as,

CursorLoader cursorLoader = new CursorLoader(context, android.provider.Browser.BOOKMARKS_URI, projection, null, null,
null);
cursor = cursorLoader .loadInBackground();

Other modification is , you don't need to call reQuery in honeyComb. You have LoaderManager callbacks are there in honeyComb. That will be called if there is any change in the underlying data.

For implementing LoaderManager callbacks

- First implement the interface in your class as LoaderManager.LoaderCallbacks
- in onCreate you need to initialize the loader as
getLoaderManager().initLoader(0, null, this);
- for reQuery, you can use, getLoaderManager().restartLoader(0, null, this);
- Then you need to override three methods in it as,
- onCreateLoader()
- onLoadFinished()
- onLoaderReset()

Androidians