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.
Android笔记01--手机振动的更多相关文章
- Android笔记: 实现手机震动效果
1.震动是系统的服务,首先需添加震动权限 <uses-permission android:name="android.permission.VIBRATE" /> 2 ...
- delphi 手机振动 IOS Android
delphi 手机振动 IOS Android delphi 手机振动 IOS Android 振动 https://community.embarcadero.com/blogs/entry/ho ...
- Android笔记——Android中数据的存储方式(二)
我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...
- 使用Vibrator控制手机振动
import android.os.Bundle;import android.os.Vibrator;import android.app.Activity;import android.app.S ...
- Android摇一摇振动效果Demo
前言 在微信刚流行的时候,在摇一摇还能用来那啥的时候,我也曾深更半夜的拿着手机晃一晃.当时想的最多的就是.我靠,为神马摇一下须要用这么大的力度,当时我想可能腾讯认为那是个人性的设计.后来才发觉 ...
- 《30天自制操作系统》笔记(01)——hello bitzhuwei’s OS!【转】
转自:http://www.cnblogs.com/bitzhuwei/p/OS-in-30-days-01-hello-bitzhuwei-OS.html 阅读目录(Content) 最初的OS代码 ...
- android BLE Peripheral 手机模拟设备发出BLE广播 BluetoothLeAdvertiser
android 从4.3系统开始可以连接BLE设备,这个大家都知道了.iOS是从7.0版本开始支持BLE. android 进入5.0时代时,开放了一个新功能,手机可以模拟设备发出BLE广播, 这个新 ...
- Android笔记(七十三) Android权限问题整理 非常全面
Android权限系统非常庞大,我们在Android系统中做任何操作都需要首先获取Android系统权限,本文记录了所有的Android权限问题,整理一下分享给大家. 访问登记属性 android.p ...
- 软件测试之loadrunner学习笔记-01事务
loadrunner学习笔记-01事务<转载至网络> 事务又称为Transaction,事务是一个点为了衡量某个action的性能,需要在开始和结束位置插入一个范围,定义这样一个事务. 作 ...
随机推荐
- luogu P4843 清理雪道
嘟嘟嘟 这其实就是一个最小流的板子题.把每一条边的流量至少为1,然后建立附加源汇跑一遍最大流,连上\(t, s\),再跑一遍最大流就是答案. 刚开始我想错了:统计每一个点的出度和入度,去两者较大值\( ...
- Hdu Bomb(数位DP)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submiss ...
- Pycharm下将py文件打包成exe文件
1. 在PyCharm下安装PyInstaller 1. 首先,打开自己要发布的工程 2. 点击底部的[Terminal]打开终端,中输入命令pip install pyinstaller后回车, ...
- Django-事务和锁
一.事务 1.全局开启事务 在Web应用中,常用的事务处理方式是将每个请求都包裹在一个事务中.这个功能使用起来非常简单,你只需要将它的配置项ATOMIC_REQUESTS设置为True. 它是这样工作 ...
- ARP 之 发送请求arp_solicit
概述 arp_solicit用来发送ARP请求,首先会根据ARP_ANNOUNCE参数来选取源地址,然后判断是否达到内核发送次数上限,未达到则调用内核arp_send_dst函数发送,如果达到上限,则 ...
- Twisted框架学习
Twisted是用Python实现的基于事件驱动的网络引擎框架,是python中一个强大的异步IO库.理解twisted的一个前提是弄清楚twisted中几个核心的概念: reactor, Proto ...
- 封装带SSH跳板机的MYSQL
一.封装带SSH跳板机的MYSQL 二.配置settting import pymysql from sshtunnel import SSHTunnelForwarder class MyDb(ob ...
- git 命令简洁手册
1.从当前目录初始化 git init 2.对文件进行跟踪 或 将已跟踪的文件放到暂缓区 或 把有冲突的文件标记为已解决状态 git add <file> 3.从现有仓库克隆 git c ...
- leetcode84 柱状图
O(n^2) time 应用heights[r]<=heights[r+1]剪枝: class Solution { public: int largestRectangleArea(vecto ...
- <HTML>在一个表格内嵌套另一个表格时,如何居中?
在一个表格内嵌套另一个表格时,如何居中? 假设大表格为: <table id="tableRow"> <tr> <th>City</th& ...