任何人都可以告诉如何从活动到服务传递字符串或整数。我试图粘贴一个整数setpossition(4),但是它并不需要,总是在启动时需要0 Service我不知道为什么我不能通过使用Service的实例从Activity进行操作。
public class MainMP3 extends Activity{
Button play,stop,prev,next,list;
static final String MEDIA_PATH = new String("/sdcard/");
Activity main_activity;
@Override
public void onCreate(Bundle savedInstanceState) {
main_activity=this;
super.onCreate(savedInstanceState);
setContentView(R.layout.mp3interface);
play= (Button) findViewById(R.id.play);
stop= (Button) findViewById(R.id.stop);
prev= (Button) findViewById(R.id.prev);
next= (Button) findViewById(R.id.next);
list= (Button) findViewById(R.id.listofsongs);
play.setOnClickListener(new StartClick());
stop.setOnClickListener(new StopClick());
prev.setOnClickListener(new PullClick());
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
list.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i= new Intent(MainMP3.this,songlist.class);
startActivity(i);
}
});
}
ServiceMP3 service = null; …Run Code Online (Sandbox Code Playgroud) 嗨,我的Eclipse上没有额外的模拟器命令行选项文本框,我必须从该文本框中提供一些参数,但它不在运行配置 - >目标是否有任何其他方式我如何给出这些参数?
感谢名单,
我知道这是我的第二个类似帖子,但我认为之前的帖子我没有人在看.
它返回NullPointerException时,我点击播放按钮,我想停止按钮,它应该会返回1,它崩溃时,我点击播放按钮getCount将()方法,这是在服务类的值绑定.这是活动类:
public class MainMP3 extends Activity{
Button stop;
static final String MEDIA_PATH = new String("/sdcard/");
Button data_display;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mp3interface);
startService(new Intent(MainMP3.this, ServiceMP3.class));
stop= (Button) findViewById(R.id.stop);
// to stop service
//stopService(new Intent(MainMP3.this, ServiceMP3.class));
Button button = (Button)findViewById(R.id.play);
button.setOnClickListener(new StartClick());
}
private ServiceMP3 service = null;
private ServiceConnection connection = new ServiceConnection() {
@Override // Called when connection is made
public void onServiceConnected(ComponentName cName, IBinder binder) {
service = ((ServiceMP3.SlowBinder)binder).getService();
}
@Override //
public …Run Code Online (Sandbox Code Playgroud)