主要代码:
Activity中
class onStartServiceClickListener implements OnClickListener
{
public void onClick(View v)
{
IP = editTextIP.getText().toString();
Port = Integer.parseInt(editTextPort.getText().toString());
Log.v("IP", IP);
Log.v("Port", editTextPort.getText().toString());
Intent intent=new Intent();
intent.putExtra("IP", IP);
intent.putExtra("Port", Port);
intent.setClass(MainActivity.this,SendGPSService.class);
startService(intent);
}
}
Service中
public void onCreate()
{
super.onCreate();
// new ClientThread("10.13.33.136", 5000); //线程正常执行
}
public int onStartCommond(Intent intent, int flags, int startId)
{
// 不能执行,换成new ClientThread("10.13.33.136", 5000); 也不行
new ClientThread(intent.getStringExtra("IP"), intent.getIntExtra("Port", 5000));
Log.v("Service IP", intent.getStringExtra("IP"));// 因为Logcat中不打印这些信息,所以判断onStartCommond没有调用
Log.v("Service Port", intent.getIntExtra("Port", 5000) + "");
Log.v("Service IP", "onStartCommond!");
return super.onStartCommand(intent, flags, startId);
}
看起来是onStartCommond没有调用的原因,不知道哪里出错了
------解决思路----------------------
你写错了一个字母,应该是
public int onStartCommand(Intent intent, int flags, int startId)
你把a写成了o
[email protected]