我有一个服务在后台运行,使用webservice检查一些数据。如果有数据,那么我需要在我的应用程序中显示一个弹出窗口。并且我需要一个提供给按钮发回状态,因为我已通过单击按钮查看了数据。需要使用服务弹出一个
任何人都可以帮助我的示例代码。
我有一个服务在后台运行,使用webservice检查一些数据。如果有数据,那么我需要在我的应用程序中显示一个弹出窗口。并且我需要一个提供给按钮发回状态,因为我已通过单击按钮查看了数据。需要使用服务弹出一个
任何人都可以帮助我的示例代码。
你可以使用android的通知服务。我认为这适合您的应用程序。对于弹出窗口,您可以创建该通知的onclick对话框。并且为了发送一些数据或状态,从dailog框变得更容易。
下面是示例
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);
}
notification是优选的方式。
但是如果你真的想弹出一些全局对话框,那么看看这个post,这真的很有帮助。