zoukankan      html  css  js  c++  java
  • Android笔记01--手机振动

    一、android任务栈  不懂?

    栈:先进后出

    队列:先进先出 

    任务栈Task中:打开一个Activity叫进栈 关闭一个activit出栈 

    任务栈是用来维护Activity的、是用来维护用户的操作体验

    我们操作的Activity永远是任务栈的栈顶的Activity

    说应用程序退出了 实际上任务栈清空,进程并没有结束

    二、activity四种启动模式-------注意是加在activity中。

    ①standard标准启动模式

    standard标准启动模式在activity的配置文件中设置android:launchMode="standard"

    每打开一个activity就会完成一次进栈,每关闭一个activity就会完成一次出栈。如果在跳转activity的时候,不及时关闭activity

    ②singletop启动模式

    singletop单一顶部模式在activity的配置文件中设置android:launchMode="singleTop"

    如果任务栈的栈顶存在这个要开启的activity,不会重新的创建activity,而是复用已经存在的activity。保证栈顶如果存在,不会重复创建。

    应用场景:浏览器的历史书签页

    ③singleTask单一任务栈启动模式

    singleTask单一任务栈模式在activity的配置文件中设置android:launchMode="singleTask"

    在当前任务栈里面只能有一个实例存在,当开启activity的时候,就去检查在任务栈里面是否有实例已经存在,如果有实例存在就复用这个已经存在的activity,并且把这个activity上面的所有的别的activity都清空,复用这个已经存在的activity,从而保证整个任务栈里面只有一个实例存在。

    如果一个activity的创建需要占用大量的系统资源(cpu,内存)一般配置这个activity为singletask的启动模式。

    应用场景:浏览器的activity

    ④singleInstance单实例启动模式

    singleInstance启动模式非常特殊, activity会运行在自己的任务栈里面,并且这个任务栈里面只有一个实例存在

    如果你要保证一个activity在整个手机操作系统里面只有一个实例存在,使用singleInstance。

    应用场景: 来电页面

    震动实现-----this,获取上下文与getApplication()区别?

    1.权限:

    <uses-permission android:name="android.permission.VIBRATE"/>
    创建震动服务对象   
    private Vibrator mVibrator;  
    开启震动服务
    mVibrator=(Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);  
    mVibrator.vibrate(new long[]{100,100,100,1000},-1);
    取消震动           
    mVibrator.cancel(); 
    原文链接:http://www.cnblogs.com/xy95/p/5870040.html


    Class that operates the vibrator on the device.
    If your process exits, any vibration you started with will stop.

    //Vibrator类用来操作设备上的震动,如果你的线程退出了,那么启动的震动也会停止

    Vibrate with a given pattern.  //根据给定的节奏震动

    Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.

    //传递一个整型数组作为关闭和开启震动的持续时间,以毫秒为单位。第一个值表示等待震动开启的毫秒数,下一个值表示保持震动的毫秒数,这个序列值交替表示震动关闭和开启的毫秒数

    To cause the pattern to repeat, pass the index into the pattern array at which to start the repeat, or -1 to disable repeating.
    //为了重复的按设定的节奏震动,传递index参数表示重复次数,用-1表示不重复。

    Parameters
    pattern     an array of longs of times for which to turn the vibrator on or off.
    repeat     the index into pattern at which to repeat, or -1 if you don't want to repeat.

  • 相关阅读:
    如何搭建ssh服务?
    安利三款提升幸福感的chrome插件
    EF6学习笔记七:代码迁移
    EF6学习笔记六:实体拆分(Entity Spliting)实现TPT、表拆分(Table Spliting)实现TPH
    EF6学习笔记五:继承三策略
    EF6学习笔记四:一对多、多对多、一对一关系配置(Fluent API)
    EF6学习笔记三:全局约定和自定义约定,整理并记下来
    EF6学习笔记二:一些详细配置,开始设计一个稍微能用的数据模型
    EF6学习笔记一:code-first简单创建数据库、表的一些过程
    Spring Cloud微服务实战 打造企业级优惠券系统 2-9 Spring Data JPA
  • 原文地址:https://www.cnblogs.com/BlueFire-py/p/8612147.html
Copyright © 2011-2022 走看看