Call the worker class from the notification bar
I am developing an online radio application. The application runs in the background. When I click the NotificationManager, the radio classes start working again. I want to call radio classes that work. How can I do?
player = MediaPlayer.create(this, Uri.parse("http://...../playlist.m3u8"));
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer player) {
}
});
player.start();
final int notificationID = 1234;
String msg = "mesajjj";
Log.d(TAG, "Preparing to update notification...: " + msg);
NotificationManager mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, RadioClass.class);
// Here RadioClass works again. But RadioClass is already working. I need to call RadioClass that works.
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.logotam)
.setContentTitle("Test FM")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(pendingIntent);
mNotificationManager.notify(notificationID, mBuilder.build());
+3
source to share
1 answer
If you want to go back to the same activity you are currently using, you can do it like this:
Add the following tag to your AndroidManifest.xml:
<activity
........
android:launchMode="singleTop" >
........
</activity>
Change your PendingIntent like this:
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
With these changes, you ensure that your activity only has one instance at any given time. In your activity class, you can also override the onNewIntent method:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
}
This method will handle all additional calls to your activity.
+1
source to share