Android samples API Demos之UI篇3(Activitytasks——DocumentCentricApps)

Android DocumentCentricRecents Sample

Sample demonstrating the basic usage of the new 'Document Centric Apps' API. It let's you create new documents in the system overview menu and persists its state through reboots.
示例演示了新API 的基本用法——以'文档为中心的应用 ,它让您创建新文档中获取到重新启动的相关的数据和状态。

这个例子没有太多的知识点,主要是新的api的运用,而且要求API版本是21及以上。关于详细的大家可以去看:http://blog.csdn.net/lincyang/article/details/45287599
  <activity android:name="com.example.android.documentcentricapps.DocumentCentricActivity"
                  android:label="@string/app_name"
                  android:persistableMode="persistAcrossReboots"><!--就是这个东西啦-->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.android.documentcentricapps.NewDocumentActivity"
            android:label="@string/activity_new_document_title" >
        </activity>

DocumentCentricActivity 类:
public class DocumentCentricActivity extends Activity {

    private final static String TAG = "DocumentCentricActivity";

    public final static String KEY_EXTRA_NEW_DOCUMENT_COUNTER = "KEY_EXTRA_NEW_DOCUMENT_COUNTER";

    private static int mDocumentCounter = 0;
  @Override//读取保存的数据
    public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onPostCreate(savedInstanceState, persistentState);
        // Restore state from PersistableBundle
        if (persistentState != null) {
            mDocumentCounter = persistentState.getInt(KEY_EXTRA_NEW_DOCUMENT_COUNTER);
        }
    }


    @Override//保存相关的数据
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        outPersistentState.putInt(KEY_EXTRA_NEW_DOCUMENT_COUNTER, mDocumentCounter);
        super.onSaveInstanceState(outState, outPersistentState);
    }

//创建新的Task
    public void createNewDocument(View view) {
        boolean useMultipleTasks = mCheckbox.isChecked();
        final Intent newDocumentIntent = newDocumentIntent();
        if (useMultipleTasks) {
            /*
            When {@linkIntent#FLAG_ACTIVITY_NEW_DOCUMENT} is used with {@link Intent#FLAG_ACTIVITY_MULTIPLE_TASK}
            the system will always create a new task with the target activity as the root. This allows the same
            document to be opened in more than one task.
             */
            newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        }
        startActivity(newDocumentIntent);
    }
}
另外的NewDocumentActivity Class 其中也没有什么重要的东东就不多说了。

下面是截图,这个需要点击查看进程列表才能看到,同时需要你在创建了一个新文档的时候按home回到桌面,再一次创建新应用,你就可以看到两个文档类了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值