2012-03-10 64 views
0

我有一個服務在後臺運行,使用webservice檢查一些數據。如果有數據,那麼我需要在我的應用程序中顯示一個彈出窗口。並且我需要一個提供給按鈕發回狀態,因爲我已通過單擊按鈕查看了數據。需要使用服務彈出一個

任何人都可以幫助我的示例代碼。

回答

0

你可以使用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); 
} 
0

notification是優選的方式。

但是如果你真的想彈出一些全局對話框,那麼看看這個post,這真的很有幫助。

相關問題