package gr.mybook.myintentservice;

import gr.mybook.myintentservice.Activity_1.ResponseReceiver;
import android.app.IntentService;
import android.content.Intent;

public class myService extends IntentService {
    public static final String PARAM_IN_MSG = "imsg";
    public static final String PARAM_OUT_MSG = "omsg";
    public static final String msg2="SERVICE COMPLETED";

    // Constructor with the name of the service
    public myService() {
         super("myService");
    }

	@Override
	protected void onHandleIntent(Intent arg0) {
		// Gets the incoming Intent's "data" value
		String action=arg0.getStringExtra(PARAM_IN_MSG);
		if (Activity_1.msg1.equals(action)) {
			try{
				Thread.sleep(1000);
			} catch (Exception e){
				e.printStackTrace();
			}
		}

		// The service is finished
		Intent broadcastIntent = new Intent();
		broadcastIntent.setAction(ResponseReceiver.ACTION_RESP);
		broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
		broadcastIntent.putExtra(PARAM_OUT_MSG, msg2);
		sendBroadcast(broadcastIntent);
	}
}
