Can start 2 services from the same activity and ca

2019-08-28 22:24发布

I have 2 services to get data from the accelerometer and microphone and 1 activity to get GPS data. I want to run these 3 things at the same time. I want to know is that possible in Android. While the GPS Activity running and display the data on the UI, other 2 services alse should run in the background.

If it is possible is the way correct that I gave to start two services from my GPS Activity class and run those 3 thing at the same time. Please any one hlp me. Thank you.

`

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


    gpsManager = new GPSManager();

    gpsManager.startListening(getApplicationContext());
    gpsManager.setGPSCallback(this);

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

    measurement_index = AppSettings.getMeasureUnit(this);
    Intent i=getIntent();
     number=i.getStringExtra("NUMBER");
     startService(new Intent(GPS2Activity.this, GforceService.class));
     startService(new Intent(GPS2Activity.this,SPLService.class));



} `

GforceService and SPLService are my 2 services

1条回答
啃猪蹄的小仙女
2楼-- · 2019-08-28 23:00

Yes, you can start 2 services and have them running in parallel with your Activities.

查看更多
登录 后发表回答