Roll NDK to pick std::deque patch.
[android_tools.git] / sdk / tools / templates / other / IntentService / root / src / app_package / IntentService.java.ftl
blobc6848ef379334a50b29ac9a65a569785bc842bb4
1 package ${packageName};
3 import android.app.IntentService;
4 import android.content.Intent;
5 <#if includeHelper>import android.content.Context;</#if>
7 /**
8  * An {@link IntentService} subclass for handling asynchronous task requests in
9  * a service on a separate handler thread.
10  * <p>
11 <#if includeHelper>
12  * TODO: Customize class - update intent actions, extra parameters and static
13  * helper methods.
14 <#else>
15  * TODO: Customize class - update intent actions and extra parameters.
16 </#if>
17  */
18 public class ${className} extends IntentService {
19 <#if !includeHelper>
20     // TODO: Rename actions, choose action names that describe tasks that this
21     // IntentService can perform, e.g. ACTION_FETCH_NEW_ITEMS
22     public static final String ACTION_FOO = "${packageName}.action.FOO";
23     public static final String ACTION_BAZ = "${packageName}.action.BAZ";
25     // TODO: Rename parameters
26     public static final String EXTRA_PARAM1 = "${packageName}.extra.PARAM1";
27     public static final String EXTRA_PARAM2 = "${packageName}.extra.PARAM2";
28 <#else>
29     // TODO: Rename actions, choose action names that describe tasks that this
30     // IntentService can perform, e.g. ACTION_FETCH_NEW_ITEMS
31     private static final String ACTION_FOO = "${packageName}.action.FOO";
32     private static final String ACTION_BAZ = "${packageName}.action.BAZ";
34     // TODO: Rename parameters
35     private static final String EXTRA_PARAM1 = "${packageName}.extra.PARAM1";
36     private static final String EXTRA_PARAM2 = "${packageName}.extra.PARAM2";
38     /**
39      * Starts this service to perform action Foo with the given parameters. If
40      * the service is already performing a task this action will be queued.
41      *
42      * @see IntentService
43      */
44     // TODO: Customize helper method
45     public static void startActionFoo(Context context, String param1, String param2) {
46         Intent intent = new Intent(context, ${className}.class);
47         intent.setAction(ACTION_FOO);
48         intent.putExtra(EXTRA_PARAM1, param1);
49         intent.putExtra(EXTRA_PARAM2, param2);
50         context.startService(intent);
51     }
53     /**
54      * Starts this service to perform action Baz with the given parameters. If
55      * the service is already performing a task this action will be queued.
56      *
57      * @see IntentService
58      */
59     // TODO: Customize helper method
60     public static void startActionBaz(Context context, String param1, String param2) {
61         Intent intent = new Intent(context, ${className}.class);
62         intent.setAction(ACTION_BAZ);
63         intent.putExtra(EXTRA_PARAM1, param1);
64         intent.putExtra(EXTRA_PARAM2, param2);
65         context.startService(intent);
66     }
67 </#if>
69     public ${className}() {
70         super("${className}");
71     }
73     @Override
74     protected void onHandleIntent(Intent intent) {
75         if (intent != null) {
76             final String action = intent.getAction();
77             if (ACTION_FOO.equals(action)) {
78                 final String param1 = intent.getStringExtra(EXTRA_PARAM1);
79                 final String param2 = intent.getStringExtra(EXTRA_PARAM2);
80                 handleActionFoo(param1, param2);
81             } else if (ACTION_BAZ.equals(action)) {
82                 final String param1 = intent.getStringExtra(EXTRA_PARAM1);
83                 final String param2 = intent.getStringExtra(EXTRA_PARAM2);
84                 handleActionBaz(param1, param2);
85             }
86         }
87     }
89     /**
90      * Handle action Foo in the provided background thread with the provided
91      * parameters.
92      */
93     private void handleActionFoo(String param1, String param2) {
94         // TODO: Handle action Foo
95         throw new UnsupportedOperationException("Not yet implemented");
96     }
98     /**
99      * Handle action Baz in the provided background thread with the provided
100      * parameters.
101      */
102     private void handleActionBaz(String param1, String param2) {
103         // TODO: Handle action Baz
104         throw new UnsupportedOperationException("Not yet implemented");
105     }