Java tutorial
/* 50AH-code ========= 50 Android Hacks (http://manning.com/sessa/) book source code Copyright (c) 2012 Manning Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /******************************************************************************* * Copyright (c) 2012 Manning * See the file license.txt for copying permission. ******************************************************************************/ package com.manning.androidhacks.hack046.service; import com.manning.androidhacks.hack046.helper.NotificationHelper; import android.app.IntentService; import android.content.Intent; import android.util.Log; public class MsgService extends IntentService { private static final String TAG = MsgService.class.getCanonicalName(); public static final String MSG_RECEIVE = "msg_receive"; public static final String MSG_DELETE = "msg_delete"; public static final String MSG_REPLY = "msg_reply"; public static final String MSG_REPLY_KEY = "msg_reply_key"; public MsgService() { super(TAG); } public MsgService(String name) { super(name); } @Override protected void onHandleIntent(Intent intent) { if (MSG_RECEIVE.equals(intent.getAction())) { handleMsgReceive(); } else if (MSG_DELETE.equals(intent.getAction())) { handleMsgDelete(); } else if (MSG_REPLY.equals(intent.getAction())) { handleMsgReply(intent.getStringExtra(MSG_REPLY_KEY)); } } private void handleMsgReply(String msg) { Log.d(TAG, "replying with msg: " + msg); NotificationHelper.dismissMsgNotification(this); } private void handleMsgDelete() { Log.d(TAG, "Removing msg..."); NotificationHelper.dismissMsgNotification(this); } private void handleMsgReceive() { NotificationHelper.showMsgNotification(this); } }