如何将类绑定到我的服务?

时间:2015-05-10 16:47:38

标签: java android methods service binding

我已经设置了服务类,我有一个类调用UserLocation,需要在后台运行,如何使用' iBinder'方法

public class MyServices extends Service {
    @Override
    public IBinder onBind(Intent intent) { //Sets up the specific service to be running in the background
        throw new UnsupportedOperationException("Not Yet Implemented");
    }

    @Override
    public void onCreate() {
        Toast.makeText(this, "Service Created", Toast.LENGTH_SHORT).show();
    } //Send an alert message showing the service is created

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        //This service will keep running until it is stopped(below) when clicked
        Toast.makeText(this, "Service Working", Toast.LENGTH_SHORT).show();
        return START_STICKY;
    }

    @Override
    public void onDestroy() {//Destroys the service/stops it from running in the background if clicked
        super.onDestroy();
        Toast.makeText(this, "Service Stopped", Toast.LENGTH_SHORT).show();
    }
}

0 个答案:

没有答案