Back to project page rocksinbanderas.
The source code is released under:
MIT License
If you think the Android project rocksinbanderas listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.player.rocksinbanderas; /* w w w .j a v a2 s . co m*/ import android.os.Bundle; import android.app.Activity; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageButton; public class MainActivity extends Activity implements OnClickListener { public static ImageButton btnPlay; public Intent playerService; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnPlay = (ImageButton) findViewById(R.id.btnPlay); btnPlay.setOnClickListener(this); } @Override protected void onResume() { Bundle extras = getIntent().getExtras(); if(extras!=null && extras.getBoolean(PlayerService.PLAYING, false)) btnPlay.setImageResource(R.drawable.ic_media_pause); super.onResume(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnPlay: playerService = new Intent(this, PlayerService.class); startService(playerService); break; } } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); if (!PlayerService.mp.isPlaying()) { stopService(playerService); cancelNotification(); } } // -- Cancel Notification public void cancelNotification() { String notificationServiceStr = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(notificationServiceStr); mNotificationManager.cancel(PlayerService.NOTIFICATION_ID); } }