zoukankan      html  css  js  c++  java
  • [Android Samples视频系列之ApiDemos] AppActivityRedirection

    1.Demo说明与演示

    Redirection这个Demo会涉及到三个Acitivity: RedirectEnter, RedirectMain,RedirectGetter。其Main Activity是RedirectEnter,它启动RedirectMain,然后在RedirectMain中根据条件来决定是否再启动RedirectGetter。主要知识点是SharedPreference的使用.

    Demo效果图如下:


    2.视频讲解

    http://www.eyeandroid.com/thread-10683-1-1.html

    3.Demo分析

    Redirection示例涉及到三个Acitivity: RedirectEnter, RedirectMain,RedirectGetter。示例的主Activity为 RedirectEnter ,RedirectEnter 启动 RedirectMain, 而Activity 会根据某个条件来决定是否将应用的控制权传给RedirectGetter 或是保持在RedirectMain。

    12_1.png

    应用代码中使用到了Shared Preferences (在之前的示例中介绍过)。 RedirectMain 将检查某个shared preferences 值是否存在:

     
    1. // Retrieve the current text preference.  If there is no text  
    2. // preference set, we need to get it from the user by invoking the  
    3. // activity that retrieves it.  To do this cleanly, we will  
    4. // temporarily hide our own activity so it is not displayed until the  
    5. // result is returned.  
    6. if (!loadPrefs()) {  
    7.  Intent intent = new Intent(this, RedirectGetter.class);  
    8.  startActivityForResult(intent, INIT_TEXT_REQUEST);  
    9. }  

    其它用到的还有startActivityForResult 。这个例子没有什么新的知识,只是涉及到了三个Activity。演示了如何根据条件触发不同的Activity,将应用控制权Redirection到不同的Activity。

    这个例子用户点击“Go”按钮,RedirectEnter 启动RedirectMain ,RedirectMain 会根据shared preferences是否有值决定是否redirect 到RedirectGetter, 第一次或是点击”Clear and Exit”后,shared preferences 中不含有text值,应用会显示RedirectGetter 来取的用户输入,此时如果用户输入并“Apply”后,RedirectGetter将在Shared Preference储存textView 的值。此后,按“Back” 退回Activity List再启动RedirectEnter,按“GO”,由于Shared Preferences中有值,RediectMain不会把应用的控制权Redirect到RedirectGetter.

  • 相关阅读:
    Android五天乐(第三天)ListFragment与ViewPager
    Thinking in States
    红黑树上的连接操作
    [LeetCode][Java] Binary Tree Level Order Traversal
    使用IR2101半桥驱动电机的案例
    HDU 4782 Beautiful Soup(模拟)
    C语言之基本算法38—格式化输出10000以内的全部完数
    远在美国的凤姐为何选择回国理財?
    2014-7-20 谁还认得这几本书?
    360在线笔试---反思两道题
  • 原文地址:https://www.cnblogs.com/eyeandroid/p/2788360.html
Copyright © 2011-2022 走看看