我按照以下方式在我的活动中启动服务。服务启动后,我关闭了活动。如果我再次启动 Activity,我想从服务接收一些信息。我怎样才能做到这一点?
// Activity
@Override
public void onCreate(Bundle savedInstanceState)
{
// here I want to receive data from Service
}
Intent i=new Intent(this, AppService.class);
i.putExtra(AppService.TIME, spinner_time.getSelectedItemPosition());
startService(i);
// Service
public class AppService extends Service {
public static final String TIME="TIME";
int time_loud;
Notification note;
Intent i;
private boolean flag_silencemode = false;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
time_loud = intent.getIntExtra(TIME, 0);
play(time_loud);
return(START_NOT_STICKY);
}