我正在开发一个Android应用程序,我需要制作一个按钮,该按钮将作为Android服务播放和停止的播放/停止按钮。播放按钮用于startActivity();停止按钮用于stopActivity();我该怎么做? 最佳答案 你只需要像这样声明一个标志变量并根据标志值声明onclick()的主体。publicclassServiceActivityextendsActivity{Buttonplay;intbutton_status=1;@OverridepublicvoidonCreate(BundlesavedInstanceS
我正在使用以下语句停止在后台运行的下载服务(扩展IntentService):context.stopService(intent);但是这个语句并不是立即调用服务的onDestory()方法,而是需要一段时间才能调用服务的onDestroy()方法。@OverridepublicvoidonDestroy(){Log.d("JSLog","ondestroycalled");super.onDestroy();}点击stopService()语句后我应该做什么,它应该立即调用服务的onDestroy()方法。 最佳答案 就我而言,
主要ActivitypublicclassMainActivityextendsActionBarActivity{Contextc=this;Intenti;protectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Buttonb=(Button)findViewById(R.id.button1);Buttonb1=(Button)findViewById(R.id.button2);b.setOn
我在停止播放音频文件的服务时遇到了很大的问题。我想在播放另一个文件之前停止当前服务。Activity:publicvoidplayTrack(Viewview){Intenti=newIntent(this,playService.class);i.setAction("com.c0dehunterstudios.relaxer.PLAY");if(isPlaying){stopService(i);isPlaying=false;Log.v("ACTIVITY","Stopping..");}startService(i);isPlaying=true;}服务:@Overridepu
调用有什么区别stopSelf(),stopSelf(int)或stopService(newIntent(this,MyServiceClass.class))在onStartCommand()内?例如,如果我以这种方式启动相同的服务两次:...IntentmyIntent1=newIntent(AndroidAlarmService.this,MyAlarmService.class);myIntent1.putExtra("test",1);IntentmyIntent2=newIntent(AndroidAlarmService.this,MyAlarmService.clas