• WP7学习笔记(三)


    一、WP7多任务的模拟
    1)应用程序模型只支持在前台执行
    2)如果另外一个程序在你的程序正在运行的时候启动,程序收到一个将要被终止的事件通知
    3)应用从前台离开的时刻并没有被马上终止,如果需要保留状态,就要自己编写一些逻辑来处理这些事情
    4)在程序关闭状态下,可以通过web service向程序发送信息以及更新程序状态
    多任务模拟机制:
    二、Tombstone
    1)可执行模式:Tombstonign、PageState、Application state、President data,Transient state,Tombstoning和Transient state模式下模拟多任务,在Tombstone模式下,应用被操作系统Terminate,就需要保存Transient state,以备于应用复活后恢复应用原状态
    2)Lifecycle包括:Launching、Running、Closing、Deactivating,Activating这五种运行态,Deactivating,Activating就是Tombstone下的运行态。在这两个运行态下可以完成唤醒后的状态或数据的转移
    3)PhoneApplicationService,保存状态信息
    代码:
           protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
            {
              
                if (PhoneApplicationService.Current.State.ContainsKey("Data"))
                    PhoneApplicationService.Current.State.Remove("Data");
                PhoneApplicationService.Current.State["Data"] = Txt_Msg.Text;
                base.OnNavigatingFrom(e);
            }
            protected override void OnOrientationChanged(OrientationChangedEventArgs e)
            {
                if(PhoneApplicationService.Current.State.ContainsKey("Data"))
                    Txt_Msg.Text=PhoneApplicationService.Current.State["Data"].ToString();
                base.OnOrientationChanged(e);
               
            }
    三、Push Notification
    为手机端应用和webservice之间建立了一条专用、持久、稳定的通道来推送通知。当通道建立后,手机端应用可以接受webservice的任何信息。
    其中信息可分为以下几类
    1.Tile Notification:可以改变Quick Lanuch area内的图标内容(图片、文字等)的方式,但需要程序被Pin to Start
    2.Toast Notification:在屏幕上面可以显示一个提示栏的方式,当点击提示栏可以打开应用程序
    3.RawNotification:直接使用Http方式来接受(Http polling)通知的方式。是不可见的,以后台方式传送通知
    ——创建客户端代码:
    HttpChannel = new HttpNotificationChannel(ChannelName, "TestService");
    httpChannel.Open();
    //绑定notification
    httpChannel.BindToShellToast();
    httpChannel.BindToShellTile(uris);
    //获取notification channel URI
    httpChannel.ChannelUriUpdated += new
    EventHandler<NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated);
    //获取Raw notification
    httpChannel.HttpNotificationReceived += new
    EventHandler<HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived);
    // 获取Toast notification
    httpChannel.ShellToastNotificationReceived += new
    EventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived);
    // 获取Push notification error message
    httpChannel.ErrorOccurred += new
    EventHandler<NotificationChannelErrorEventArgs>(httpChannel_ExceptionOccurred);
    //对于Tile notification是由系统来接收的,所以没有相应的Event

    ——创建服务端:都是以Http方式发送不同的通知;需要配置相应的参数,告诉Push Notification Service所发送的类型是什么;代码如下:
    HttpWebRequest request =
    (HttpWebRequest)WebRequest.Create(channelUri);
    request.Method = WebRequestMethods.Http.Post;
    request.ContentType = "text/xml; charset=utf-8";
    request.ContentLength = notificationmessage.Length;
    request.Headers["X-MessageID"] = Guid.NewGuid().ToString();
    //设置发送的Notification类型
    request.Headers[“X-WindowsPhone-Target”] = “toast”;
    request.Headers["X-NotificationClass"] = “2”;


     

  • 相关阅读:
    Zookeeper 系列(五)Curator API
    Zookeeper 系列(四)ZKClient API
    Zookeeper 系列(三)Zookeeper API
    Zookeeper 系列(二)安装配制
    [bzoj 2393] Cirno的完美算数教室 (容斥原理+dfs剪枝)
    [Sdoi2013] [bzoj 3198] spring (hash+容斥原理)
    [bzoj 1471] 不相交路径 (容斥原理)
    [bzoj 3701] Olympic Games (莫比乌斯反演)
    [bzoj 2693] jzptab & [bzoj 2154] Crash的数字表格 (莫比乌斯反演)
    [51Nod 1244]
  • 原文地址:https://www.cnblogs.com/yja9010/p/3178786.html
Copyright © 2020-2023  润新知