Android :I/ActivityManager( 476): 不再需要 com.androidLocator.libs (pid 1047): 隐藏 #16

发布于 2024-11-26 22:07:38 字数 2547 浏览 0 评论 0原文

我是一名 Android 初级开发人员:) 在我的新应用程序中,我遇到服务问题,这是我的代码:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.LocationManager;
import android.widget.Toast;


public class OnBootReceiver extends BroadcastReceiver 
{
    private boolean service;
    @Override
    public void onReceive(Context context, Intent intent)
    {

        SharedPreferences settings = context.getSharedPreferences(LbsGeocodingActivity.PREFS_NAME, 0);
        service = settings.getBoolean("service", true);//start 
        Toast.makeText(context, "1", Toast.LENGTH_LONG).show(); 
        if(service)
        {
            Toast.makeText(context, "2", Toast.LENGTH_LONG).show(); 
            Intent i = new Intent(context, Receiver.class);     
            context.startService(i);


        }

    }

}

接收器:

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.IBinder;
import android.widget.Toast;

public class Receiver extends Service {
    private MyLocationListener myLocationListener;
    private LocationManager locationManager;

    @Override
    public void onCreate() {
      Toast.makeText(this, "Started", Toast.LENGTH_LONG).show();
          //gps
      myLocationListener=new MyLocationListener(this);

      locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
      locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 
            LbsGeocodingActivity.MINIMUM_TIME_BETWEEN_UPDATES, 
            LbsGeocodingActivity.MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
            myLocationListener
      );
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
}

我有此日志:

I/PackageParser(  476): com.androidLocator.libs: compat added android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_PHONE_STATE
I/ActivityManager(  476): Start proc com.androidLocator.libs for broadcast com.androidLocator.libs/com.androidLocator.OnBootReceiver: pid=1047 uid=10091 gids={3003, 1015}
I/ActivityManager(  476): No longer want com.androidLocator.libs (pid 1047): hidden #16

我看到 Toast 1 和 Toast 2,但没有看到 Toast Started :( 抱歉我的英语不好。

谢谢

I'm a junior development for android :)
In my new application i have a problem with service this is my code:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.LocationManager;
import android.widget.Toast;


public class OnBootReceiver extends BroadcastReceiver 
{
    private boolean service;
    @Override
    public void onReceive(Context context, Intent intent)
    {

        SharedPreferences settings = context.getSharedPreferences(LbsGeocodingActivity.PREFS_NAME, 0);
        service = settings.getBoolean("service", true);//start 
        Toast.makeText(context, "1", Toast.LENGTH_LONG).show(); 
        if(service)
        {
            Toast.makeText(context, "2", Toast.LENGTH_LONG).show(); 
            Intent i = new Intent(context, Receiver.class);     
            context.startService(i);


        }

    }

}

Receiver:

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.IBinder;
import android.widget.Toast;

public class Receiver extends Service {
    private MyLocationListener myLocationListener;
    private LocationManager locationManager;

    @Override
    public void onCreate() {
      Toast.makeText(this, "Started", Toast.LENGTH_LONG).show();
          //gps
      myLocationListener=new MyLocationListener(this);

      locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
      locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 
            LbsGeocodingActivity.MINIMUM_TIME_BETWEEN_UPDATES, 
            LbsGeocodingActivity.MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
            myLocationListener
      );
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
}

I have this log:

I/PackageParser(  476): com.androidLocator.libs: compat added android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_PHONE_STATE
I/ActivityManager(  476): Start proc com.androidLocator.libs for broadcast com.androidLocator.libs/com.androidLocator.OnBootReceiver: pid=1047 uid=10091 gids={3003, 1015}
I/ActivityManager(  476): No longer want com.androidLocator.libs (pid 1047): hidden #16

I see Toast 1 and Toast 2 but not see Toast Started :(
Sorry for my bad english.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文