Android :I/ActivityManager( 476): 不再需要 com.androidLocator.libs (pid 1047): 隐藏 #16
我是一名 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论