how to pass data from activity to running service

后端 未结 4 961
北恋
北恋 2021-02-14 02:33

I want to send data to the server periodically, I\'m using background Service for that, but I want to send when the data got updated, and updated data I\'m getting

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-14 02:33

    1.Sending data to service Upto Lolipop edition

    Intent serviceIntent= new Intent(DriverActivity.this,demoService.class);
    serviceIntent.putExtra("token", token);
    startService(serviceIntent);
    
    1. Retrieving data in Service class :

       @Override
      public int onStartCommand(Intent intent, int flags, int startId)
      {
      Toast.makeText(this, "Starting..", Toast.LENGTH_SHORT).show();
      Log.d(APP_TAG,intent.getStringExtra("token"));
      return "your flag";
      }
      

提交回复
热议问题