Android 如何在我的服务类中获取从活动类传递的值?
下面是我将值从活动类传递到服务类的代码Android 如何在我的服务类中获取从活动类传递的值?,android,service,android-intent,Android,Service,Android Intent,下面是我将值从活动类传递到服务类的代码 Intent i = new Intent(this, MyAlarmService.class); i.putExtra("rowId", rowId); startactivity(i); 我如何在我的服务类中获得rowId? 请帮帮我,你可以 Override onStart() -- you receive the Intent as a parameter, 及 那么 或 为此你可以 Override onStart() -- you re
Intent i = new Intent(this, MyAlarmService.class);
i.putExtra("rowId", rowId);
startactivity(i);
我如何在我的服务类中获得rowId?
请帮帮我,你可以
Override onStart() -- you receive the Intent as a parameter,
及
那么
或
为此你可以
Override onStart() -- you receive the Intent as a parameter,
及
那么
或
试试这个
public int onStartCommand (Intent intent, int flags, int startId)
{
super.onStartCommand(intent, flags, startId);
String id = intent.getStringExtra("rowId");
}
试试这个
public int onStartCommand (Intent intent, int flags, int startId)
{
super.onStartCommand(intent, flags, startId);
String id = intent.getStringExtra("rowId");
}
尝试:
在MyAlarmService.class中
在onStartCommand方法中写入
String rid = intent.getStringExtra("rowId", rowId);
您将得到答案。试试:
在MyAlarmService.class中
在onStartCommand方法中写入
String rid = intent.getStringExtra("rowId", rowId);
你会得到答案。你在活动中投入了额外的精力
Intent intent = new Intent(this, Service.class);
intent.putExtra("Key", "String");
你在服务课上得到额外的奖励
String ba;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
ba = intent.getStringExtra("Key");
return START_STICKY;
}
你在活动中投入了额外的精力
Intent intent = new Intent(this, Service.class);
intent.putExtra("Key", "String");
你在服务课上得到额外的奖励
String ba;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
ba = intent.getStringExtra("Key");
return START_STICKY;
}
可以是的副本可以是的副本