我正在尝试将用户从微调器中选择它的活动中的时间值传递给服务,以便音频剪辑将播放该时间长度。到目前为止,我没有收到任何错误,但该服务没有在请求的时间内播放。我没有发布 logcat,因为我没有错误,我假设这是我忽略的简单事情。我想从活动中获取 TIME_IN_MINUTES 值并让服务播放那么长时间。
服务等级
@Override
public void onStart(Intent intent, int startid) {
long time = 0;
if (intent.hasExtra("TIME_IN_MINUTESC")) {
time = intent.getLongExtra("TIME_IN_MINUTES", 1000);
}
Toast.makeText(this, "Ship Service Started for" + time,
Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
myPlayer.start();
}
}
活动课。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ship);
button2 = (Button) findViewById(R.id.btn2);
button2.setOnClickListener(this);
stop1 = (Button) findViewById(R.id.stop);
stop1.setOnClickListener(this);
spinner2 = (Spinner) findViewById(R.id.spinner2);
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,
android.R.layout.simple_spinner_item, TIME_IN_MINUTES);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter);
Intent intService = new Intent(Ship.this, Shipservice.class);
intService.putExtra("TIME_IN_MINUTES", 1000);
}
// Handle button callback
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn2:
Log.d(TAG, "onClick: starting service");
startService(new Intent(this, Shipservice.class));
break;
case R.id.stop:
Log.d(TAG, "onClick: stopping srvice");
stopService(new Intent(this, Shipservice.class));
break;
}