有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我有我的服务类设置,我有一个类调用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) 个答案