Necesito abrir una ventana emergente usando el servicio.

I have a service running in the background which check for some data using webservice.If there is data then i need to show a pop up in my application.And i need a provision to a button to send back the status as i have viewd the data by clicking the button.

Will any one help me with sample code.

preguntado el 10 de marzo de 12 a las 09:03

2 Respuestas

You can use android's notification service for this. I think that is appropriate for your application. For popup you can create dialog box onclick of that notification. And for send back some data or status it becomes lot easier from dailog box.

Aquí hay una muestra

public class NotificationService extends Service {...

   public void create_notification()
{
     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
     Notification notification = new Notification(R.drawable.ic_launcher, "Msg",System.currentTimeMillis());

     // Hide the notification after its selected
     notification.flags |= Notification.FLAG_AUTO_CANCEL;
     notification.defaults |= Notification.DEFAULT_SOUND;
 //  notification.defaults |= Notification.FLAG_NO_CLEAR;

     //notification.sound = Uri.parse("file:///sdcard/bluetooth/smsbomb.mp3");  

     Intent intent = new Intent(this, New_dialog.class);// Here specify the class that you want to be opens on click of the notification...       

     PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0); 
     notification.setLatestEventInfo(this, "GPS Notifications", "This can be data", activity);
     notification.number = count;
     count++;
     notificationManager.notify(0, notification);
}

respondido 10 mar '12, 09:03

. is a preferred way .

but if you really want to pop up some global dialog then take a look of this post ,It really helpful.

respondido 10 mar '12, 10:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.