当前位置: 首页>>代码示例>>Java>>正文


Java PersistableBundle.putInt方法代码示例

本文整理汇总了Java中android.os.PersistableBundle.putInt方法的典型用法代码示例。如果您正苦于以下问题:Java PersistableBundle.putInt方法的具体用法?Java PersistableBundle.putInt怎么用?Java PersistableBundle.putInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.os.PersistableBundle的用法示例。


在下文中一共展示了PersistableBundle.putInt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onSaveInstanceState

import android.os.PersistableBundle; //导入方法依赖的package包/类
@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
    /*
    To maintain activity state across reboots the system saves and restore critical information for
    all tasks and their activities. Information known by the system includes the activity stack order,
    each task’s thumbnails and each activity’s and task's Intents. For Information that cannot be retained
    because they contain Bundles which can’t be persisted a new constrained version of Bundle,
    PersistableBundle is added. PersistableBundle can store only basic data types. To use it
    in your Activities you must declare the new activity:persistableMode attribute in the manifest.
     */
    outPersistentState.putInt(KEY_EXTRA_NEW_DOCUMENT_COUNTER, mDocumentCounter);
    super.onSaveInstanceState(outState, outPersistentState);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:14,代码来源:DocumentCentricActivity.java

示例2: scheduleJob

import android.os.PersistableBundle; //导入方法依赖的package包/类
/**
 * Here we schedule our task and constraints to execute when are met,
 * in this case a periodic task.
 * @param context
 */
public static void scheduleJob(Context context, int duration){
    //Component we want to execute
    //we need to pass context and name of our PeriodicTaskService class
    //that will execute the task
    ComponentName serviceComponent = new ComponentName(context.getApplicationContext(), PeriodicTaskService.class);
    //the component is passed to the builder of job,
    //this builder object are the requirements
    //needed to execute our task, in this case, we need
    //that our task executes every duration seconds
    JobInfo.Builder builder = new JobInfo.Builder(/*Id of our job*/0, serviceComponent);

    //set this params to retrieve when our job finish and
    //decide how many time has to wait the next execution
    PersistableBundle extraInfo = new PersistableBundle();
    extraInfo.putInt(MainActivity.Constants.DURATION,duration);
    builder.setExtras(extraInfo);

    //Using setMinimumLatency with setOverrideDeadline together,
    //it makes something like minimum and maximum limit to execute the code, is useful
    //because minimum time for setPeriodic in Nougat are 15 minutes, so if you require
    //to execute your task in lower range of time is not going to work.
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        //minimum latency means the min limit in milliseconds JobScheduler has to wait to execute the code
        builder.setMinimumLatency(duration);
        //setOverrideDeadline means the max limit in milliseconds in which your code is
        //going to execute.
        builder.setOverrideDeadline(duration);
    }
    //For android <= M there is no problem in use setPeriodic (instead of two before), with less than 15 minutes
    else {
        builder.setPeriodic(duration);
    }


    //now that our builder object has the parameters set
    //is time to schedule it.
    //NOTE: Remember to pass application context with getApplicationContext() instead of Activity context to avoid memory leaks!!!!!!!!!!
    JobScheduler jobScheduler = (JobScheduler) context.getApplicationContext().getSystemService(Context.JOB_SCHEDULER_SERVICE);
    jobScheduler.schedule(builder.build());
}
 
开发者ID:frank240889,项目名称:JobSchedulerTest,代码行数:46,代码来源:Job.java


注:本文中的android.os.PersistableBundle.putInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。