如何从android中的Activity onCreate方法启动2个服务?

时间:2012-06-11 20:39:58

标签: android service android-activity

我想从1个活动开始两个服务并同时运行所有3个东西

`

     @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    gpsManager = new GPSManager();

    gpsManager.startListening(getApplicationContext());
    gpsManager.setGPSCallback(this);
    Toast.makeText(this, "after GPS Manager", 2000).show();

    ((TextView)findViewById(R.id.info_message)).setText(getString(R.string.info));

    measurement_index = AppSettings.getMeasureUnit(this);
    Intent i=getIntent();
     number=i.getStringExtra("NUMBER");


     Intent spl=new Intent(GPS2Activity.this,SPLService.class);
     spl.putExtra("NUMBER", number);
     startService(spl);

     Intent gforce=new Intent(GPS2Activity.this,GforceService.class);
     gforce.putExtra("NUMBER", number);
     startService(gforce);




     Toast.makeText(this, "complete on create", 2000).show();





}`

但是任何服务都没有启动。这样有什么不对吗?或者从同一活动开始2个服务同时运行的其他可能方式是什么

谢谢

0 个答案:

没有答案