Time:10-20
CodePudding user response:
you can get a map mapping once good
upload music list Service inside
flash back, of course, you get the map into a static variable, in onStartCommand again after receipt of the parameters to get, you don't get to the parameters directly from an error, not in onCreate
Quote: reference m - 5 floor oj response: Flash back, of course, you get the map into a static variable, in onStartCommand again after receipt of the parameters to get, you don't get to the parameters directly from an error, not in onCreate Thanks for elder brother! I changed again change, but don't know whether I am the "parameters" what is "parameters" don't understand why (refers to the transfer of the map key?) , the result still flash back, scratching his head. JPG The following is a code, can help me to look at again? Package com. Example. Myalarm; The import android. App. Service; The import android. Content. Intent; The import android. Media. MediaPlayer; The import android. OS. IBinder; Import the Java. Util. HashMap; Import the Java. Util. The Map; Public class MusicService extends the Service {Private String Sring; Public MusicService () {} The static Boolean isplay. MediaPlayer player; The static Map The date=new HashMap (a); @ Override Public IBinder onBind (Intent Intent) {//TODO: Return the communication channel to the service. Throw new UnsupportedOperationException (" Not yet implemented "); } @ Override Public int onStartCommand (Intent Intent, int flags, int startId) {if (! Player. IsPlaying ()) {Player. Start (); Isplay=player. IsPlaying (); } The date. The put (" bird ", R.r aw. Bird); Date. The put (" chimes ", R.r aw. Chimes); The date. The put (" cock ", R.r aw. Cock); The date. The put (" cuckoo ", R.r aw. Cuckoo); The date. The put (" notify ", R.r aw. Notify); The date. The put (" ringout ", R.r aw. Ringout); The date. The put (" water ", R.r aw. Water); Sring Sring=intent. GetStringExtra (" ");//this is received the parameters? Return super. OnStartCommand (intent, flags, startId); } @ Override Public void onCreate () {Player=MediaPlayer. Create (this date), get (Sring)); } @ Override Public void onDestroy () {Player. Stop (); Isplay=player. IsPlaying (); Player. Release (); Super. OnDestroy (); } }
Flash back, of course, you get the map into a static variable, in onStartCommand again after receipt of the parameters to get, you don't get to the parameters directly from an error, not in onCreate
Page link:https//www.codepudding.com/Mobile/69504.html