相关疑难解决方法(0)

如何检查服务是否在Android上运行?

如何检查后台服务(在Android上)是否正在运行?

我想要一个能够切换服务状态的Android活动 - 它可以让我打开它,如果它打开则关闭.

android android-service

900
推荐指数
17
解决办法
45万
查看次数

即使在Android中调用onDestroy方法,服务也不会停止

我还是新手.我使用stopService调用onDestroy方法.调用onDestroy方法,因为我可以看到toast消息.但是用于发送位置更新的无限for循环一直在运行.有什么我需要改变的吗?

public class myservice extends IntentService {
    LocationManager locationManager ;
    public myservice() {
        super(myservice.class.getName());
    }
    @Override
    protected void onHandleIntent(Intent intent) {
        String numb=intent.getStringExtra("num");
        for (;;) {
            send(numb);
        }
    }

    public IBinder onBind(Intent intent) {
        return null;
    }

    public void send(String numb) {
        locationManager = (LocationManager)this
                .getSystemService(Context.LOCATION_SERVICE);
        if (ContextCompat.checkSelfPermission( this, android.Manifest.permission.ACCESS_COARSE_LOCATION ) == PackageManager.PERMISSION_GRANTED ) {}
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        Geocoder geocoder;
        geocoder = new Geocoder(this, Locale.getDefault());
        try {
            Thread.sleep(3000);
            List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
            Toast toast1 = Toast.makeText(this, "message …
Run Code Online (Sandbox Code Playgroud)

android android-service android-studio

3
推荐指数
1
解决办法
740
查看次数

标签 统计

android ×2

android-service ×2

android-studio ×1