Thursday, July 30, 2015

How to open android applications by web browsers

It is very simple to open android application by android browser i.e.  web deep linking .

Step 1:- Add intent-filter in your activity which need to open by web browser it is either main activity or other activity .
  e.g.

 <activity
            android:name=".YourActivity"
            android:label="@string/title_activity_your_deep_linking">
            <intent-filter>
                <data android:scheme="yourScheme" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>

  Step 2:- Create request link which will be executed by mobile browsers .

 <html>
<body>
<a href="yourScheme:?key1=4444&amp;key2=E110123&amp;type=wabpage&amp;status=1&amp;extra=value">click to open App</a>
</body>
</html
Note :yourScheme is app scheme followed by query string .

 Step 3:- Get data in YourActivity class by following android APIs .

  Uri uri = getIntent().getData();
 String key1= uri.getQueryParameter("key1").toString();
 String key2= uri.getQueryParameter("key2").toString();
                                        ...
                                        ...
                                        ...




Enjoy  android interesting feature  which will help you for referring for android application by browsers . 

Thursday, July 23, 2015

Handler vs AsyncTask vs Thread

 A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.
There are two main uses for a Handler: (1) to schedule messages and runnables to be executed as some point in the future; and (2) to enqueue an action to be performed on a different thread than your own.
      1.   AsyncTask and Handler are written in Java (internally they use a Thread), so everything              you        can do with Handler or AsyncTask, you can achieve using a Thread too.
     2.     An AsyncTask is used to do some background computation and publish the result to the        UI  thread (with optional progress updates). Since you're not concerned with UI, then                   a Handler or Threadseems more appropriate.

          3.  Handler allows you to send and process Message and Runnable objects associated with     a  thread's MessageQueue.
         4.  When Handler communicates, it just gives a message to caller thread and it will wait to  process. Complicated? Just remember that Handler can communicate with the caller thread in  a safe way.