Android中Activity启动模式详解

2017年6月19日 没有评论

  在Android中每个界面都是一个Activity,切换界面操作其实是多个不同Activity之间的实例化操作。在android中Activity的启动模式决定了Activity的启动运行方式。

Android总Activity的启动模式分为四种:

Activity启动模式设置:

<activity android:name=”.MainActivity” android:launchMode=”standard” />

Activity的四种启动模式:

1. standard

默认启动模式,每次激活Activity时都会创建Activity,并放入任务栈中。

2. singleTop

如果在任务的栈顶正好存在该Activity的实例, 就重用该实例,否者就会创建新的实例并放入栈顶(即使栈中已经存在该Activity实例,只要不在栈顶,都会创建实例)。

3. singleTask

如果在栈中已经有该Activity的实例,就重用该实例(会调用实例的onNewIntent())。重用时,会让该实例回到栈顶,因此在它上面的实例将会被移除栈。如果栈中不存在该实例,将会创建新的实例放入栈中。

4. singleInstance

在一个新栈中创建该Activity实例,并让多个应用共享改栈中的该Activity实例。一旦改模式的Activity的实例存在于某个栈中,任何应用再激活改Activity时都会重用该栈中的实例,其效果相当于多个应用程序共享一个应用,不管谁激活该Activity都会进入同一个应用中

大家遇到一个应用的Activity供多种方式调用启动的情况,多个调用希望只有一个Activity的实例存在,这就需要Activity的onNewIntent(Intent intent)方法了。只要在Activity中加入自己的onNewIntent(intent)的实现加上Manifest中对Activity设置lanuchMode=“singleTask”就可以。

onNewIntent()非常好用,Activity第一启动的时候执行onCreate()—->onStart()—->onResume()等后续生命周期函数,也就时说第一次启动Activity并不会执行到onNewIntent(). 而后面如果再有想启动Activity的时候,那就是执行onNewIntent()—->onResart()——>onStart()—–>onResume().  如果android系统由于内存不足把已存在Activity释放掉了,那么再次调用的时候会重新启动Activity即执行onCreate()—->onStart()—->onResume()等。

当调用到onNewIntent(intent)的时候,需要在onNewIntent() 中使用setIntent(intent)赋值给Activity的Intent.否则,后续的getIntent()都是得到老的Intent。

分类: Android 标签: ,

git命令

2017年6月16日 没有评论

git clone git@github.com-personal:H***/ffmpeg.git
cd ffmpeg/
git remote -v
git remote add upstream git://source.ffmpeg.org/ffmpeg.git
git remote -v

git fetch upstream
git checkout master
git merge upstream/master

git checkout -b dev
git push –set-upstream origin dev

阅读全文…

分类: git, 命令 标签: ,

Linux下SpeedTest测速

2017年6月7日 没有评论

wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py

chmod +x speedtest.py

测试结果:$ ./speedtest.py
Retrieving speedtest.net configuration…
Testing from Psychz (104.???.???.???)…
Retrieving speedtest.net server list…
Selecting best server based on ping…
Hosted by Time Warner Cable (Los Angeles, CA) [36.79 km]: 316.038 ms
Testing download speed……………………………………………………………………..
Download: 0.91 Mbit/s
Testing upload speed……………………………………………………………………………………
Upload: 2.81 Mbit/s

阅读全文…

分类: Linux 标签: ,

VNC setup on Raspberry Pi from Ubuntu

2017年6月5日 没有评论

VNC setup on Raspberry Pi from Ubuntu

通过SSH连接:

ssh pi@192.168.0.112

默认用户名pi, 默认密码‘raspberry’

配置VNC:

sudo apt-get install tightvncserver

启动VNC:vncserver :1 -geometry 1024x600 -depth 16 -pixelformat rgb565
连接VNC:vncviewer 192.168.0.112:5901
停止VNC:vncserver -kill :1
分类: Linux 标签: , ,

修改SSH默认22端口

2017年6月5日 没有评论

首先修改配置文件
vi /etc/ssh/sshd_config

找到#Port 22一段,这里是标识默认使用22端口,修改为如下:

Port 22
Port 50000
然后保存退出

执行/etc/init.d/sshd restart
这样SSH端口将同时工作与22和50000上。

现在编辑防火墙配置:vi /etc/sysconfig/iptables

启用50000端口。
执行/etc/init.d/iptables restart

分类: Linux 标签: ,

Android暗码

2017年5月12日 没有评论

packages/apps/Dialer/src/com/android/dialer/SpecialCharSequenceMgr.java


/**
* Handles secret codes to launch arbitrary activities in the form of *#*#<code>#*#*.
* If a secret code is encountered an Intent is started with the android_secret_code://<code>
* URI.
*
* @param context the context to use
* @param input the text to check for a secret code in
* @return true if a secret code was encountered
*/
static boolean handleSecretCode(Context context, String input) {
// Secret codes are in the form *#*#<code>#*#*
int len = input.length();
if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
final Intent intent = new Intent(SECRET_CODE_ACTION,
Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
context.sendBroadcast(intent);
return true;
}

return false;
}

分类: Android 标签:

一些命令

2017年5月3日 没有评论

adb root
adb remount

adb push services.jar /system/framework
adb push framework.jar /system/framework
adb push framework-res.apk /system/framework

adb push arm/boot.oat /system/framework/arm
adb push arm/boot.art /system/framework/arm
adb push arm/boot-framework.oat /system/framework/arm
adb push arm/boot-framework.art /system/framework/arm

adb push arm64/boot.oat /system/framework/arm64
adb push arm64/boot.art /system/framework/arm64
adb push arm64/boot-framework.oat /system/framework/arm64
adb push arm64/boot-framework.art /system/framework/arm64

pause
adb reboot


echo off
echo YES | copy \\ip\&lt;branch1&gt;\out\target\product\&lt;product&gt;\system\priv-app\SystemUI\SystemUI.apk .
md5sum SystemUI.apk
adb push SystemUI.apk /system/priv-app/SystemUI/SystemUI.apk
adb shell am force-stop com.android.systemui
echo on


mmm core/res &amp;&amp; mm &amp;&amp; mmm services &amp;&amp; mm

mmm -B core/res &amp;&amp; mm -B &amp;&amp; mmm -B services &amp;&amp; mm -B

分类: Android 标签: ,

How to Download/Compile Specific Parts of a ROM

2017年5月2日 没有评论

How to Download/Compile Specific Parts of a ROM

This is a tutorial about how to download and compile specific parts in AOSP based roms (such as CyanogenMod, AOKP, SlimRom etc)
It’s mainly dedicated for the people who want to get more familiar with the AOSP build environment, and would like to manipulate it’s behavior to complete specific tasks.

Introduction:
Downloading ROM sources is done with the tool “repo”, this is the most awesome downloader in existence. Not only it looks very cool, it also reaches top speed at all times. But it’s only for linux (which is good, since when you are busy with aosp roms, you should be on linux!)
Why is it awesome? Since you decide yourself how many jobs (aka connections) you make with the server. This means you always will get top speed, there is probably no faster download method available on the Internet (except for speedtests, but they don’t count). Next to the downloading of specific parts it’s of course also handy to know how to actually compile them.

 

Chapters:
1. Download
2. Compile

3. Automate (optional)

 

Chapter 1. Download:
The easiest way of fetching for example a batch of AOSP apps is like this:

1. Choose the desired tag you want to use, in the example I will use android-4.2.2_r1
2. Now make a dir somewhere:

3. Download repo when not installed yet:

4. Enter the line that will download the initial manifest.

for AOSP:

Enter your name and email address and wait until it completes

for CM:

5. Go in the hidden “.repo” dir and change the manifest

If you don’t have decent text editor such as “gedit”, install it! “sudo apt-get install gedit”

 

For example when you only want to download the apps, just remove all lines that are not app related. simple as that

When done, save it and go a dir back in the terminal

6. Download the packages

(With a 60mb/s connection you already get the max download speed with ” -j4 ” which is the default of github)

The packages will be download as quickly as possible to your harddrive now.

 

Chapter 2. Compile:
To compile the obtained packages separately you will need a AOSP environment (or CM/AOKP etc). When you have a succesfull environment which is able to compile for your device you may enter:

now you’re theoretically ready to compile
to compile an app on the easiest way:

where “Appname” is the name of the folder placed in packages/apps/..
This also counts for “SystemUI” which is not in that folder

And the -j param again stands for the number of jobs, remember that this is compiling and not downloading, so the “standard rule” with this is, number of cores of your CPU + 1.
Which makes a regular quad core (-j5) but makes a i7 CPU with Hyper threading (-j9). When using -j16 for example on a regular quad core it could happen that your CPU will be overloaded so much that your mouse will lag all over the place.
(Linux forces the cpu to perform higher then it actually should, resulting in unwanted situations)

When having trouble, when it stops or just nags about some missing symbols or something like that.
You should try using the “-k” param, this tells the make command to keep going when a non-critical error occurs.

When having issues with the local module tags, you should enter this:

To compile other parts you also need to enter the folder name, here are some examples from /frameworks/base

or more examples:

 

Chapter 3. Automate

If you regularly want to compile specific ROM parts you can make a shell script that automates the process for you.

Make a new document with some name, for example “buildessentials”, open the file with your favorite text editor (gedit is recommended)
and place this line at the very top of your document:

This indicates that this file should call /bin/bash, which is the shell interpreter.

Under this line you should place all the single commands that you want to be executed when running the script. For example:

So your total output would be:

Now you should change the permissions of the files, which need to be RWX-RX-RX, which is 755.
This can be done by entering this in the shell:

Now you can run the script by entering:

分类: Android 标签: ,

AOSP下载代码

2017年5月1日 没有评论
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
#AOSP download command
#https://source.android.com/source/downloading
repo init -u https://android.googlesource.com/platform/manifest
repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r6

#lineageos download command
#https://wiki.lineageos.org/devices/bacon/build#download-the-source-code
cd ~/android/lineage
repo init -u https://github.com/LineageOS/android.git -b cm-14.1
repo sync -c -d -j2 --no-tags
分类: Android 标签: , ,

解决: g++: internal compiler error: Killed (program cc1plus)

2017年4月30日 没有评论

g++: internal compiler error: Killed (program cc1plus)

主要原因是内存不足,g++编译时需要大量内存, 临时使用交换分区来解决吧

sudo dd if=/dev/zero of=/swapfile bs=64M count=16

sudo mkswap /swapfile

sudo swapon /swapfile

After compiling, you may wish to

Code:

sudo swapoff /swapfile

sudo rm /swapfile

分类: Linux 标签: ,