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

来源:互联网 发布:淘宝退货率高会怎样 编辑:程序博客网 时间:2024/06/14 02:29

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
原创粉丝点击