#############################################################
# sudoers file.
#
# This file MUST be edited with the ‘visudo’ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# User privilege specification
root ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
配置示例:
############################################################################
# sudoers file.
#
# This file MUST be edited with the ‘visudo’ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
Host_Alias EPG = 192.168.1.1, 192.168.1.2
# User alias specification
# Cmnd alias specification
Cmnd_Alias SQUID = /opt/vtbin/squid_refresh, /sbin/service, /bin/rm
# Defaults specification
# User privilege specification
root ALL=(ALL) ALL
support EPG=(ALL) NOPASSWD: SQUID
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
E:\android_sdk\android-sdk-windows-1.6_r1\tools>emulator -verbose -avd avd2
emulator: found SDK root at E:\android_sdk\android-sdk-windows-1.6_r1
emulator: root virtual device file at C:\Documents and Settings\lizhongyi\.android/avd/avd2.ini
emulator: virtual device content at C:\Documents and Settings\lizhongyi\.android\avd\avd2.avd
emulator: virtual device config file: C:\Documents and Settings\lizhongyi\.android\avd\avd2.avd/config.ini
emulator: locking user data image at C:\Documents and Settings\lizhongyi\.android\avd\avd2.avd/userdata-qemu.img
emulator: locking cache image at C:\Documents and Settings\lizhongyi\.android\avd\avd2.avd/cache.img
emulator: ignoring non-existing SD Card at C:\Documents and Settings\lizhongyi\.android\avd\avd2.avd/sdcard.img: No such file or directory
emulator: found skin ‘QVGA’ in directory: E:\android_sdk\android-sdk-windows-1.6_r1/platforms\android-1.6\skins
emulator: autoconfig: -skin QVGA
emulator: autoconfig: -skindir E:\android_sdk\android-sdk-windows-1.6_r1/platforms\android-1.6\skins
emulator: keyset loaded from: C:\Documents and Settings\lizhongyi\.android\default.keyset
emulator: trying to load skin file ‘E:\android_sdk\android-sdk-windows-1.6_r1/platforms\android-1.6\skins/QVGA/layout’
emulator: skin network speed: ‘full’
emulator: skin network delay: ‘none’
emulator: registered ‘boot-properties’ qemud service
emulator: registered ‘boot-properties’ qemud service
emulator: Adding boot property: ‘qemu.sf.lcd_density’ = ’120′
emulator: argv[00] = “emulator”
emulator: argv[01] = “-kernel”
emulator: argv[02] = “E:\android_sdk\android-sdk-windows-1.6_r1/platforms\android-1.6\images\/kernel-qemu”
emulator: argv[03] = “-initrd”
emulator: argv[04] = “E:\android_sdk\android-sdk-windows-1.6_r1/platforms\android-1.6\images\/ramdisk.img”
emulator: argv[05] = “-nand”
emulator: argv[06] = “system,size=0×4200000,initfile=E:\android_sdk\android-sdk-windows-1.6_r1/platforms\android-1.6\images\/system.img”
emulator: argv[07] = “-nand”
emulator: argv[08] = “userdata,size=0×4200000,file=C:\Documents and Settings\lizhongyi\.android\avd\avd2.avd/userdata-qemu.img”
emulator: argv[09] = “-nand”
emulator: argv[10] = “cache,size=0×4200000,file=C:\Documents and Settings\lizhongyi\.android\avd\avd2.avd/cache.img”
emulator: argv[11] = “-serial”
emulator: argv[12] = “android-kmsg”
emulator: argv[13] = “-serial”
emulator: argv[14] = “android-qemud”
emulator: argv[15] = “-append”
emulator: argv[16] = “qemu=1 console=ttyS0 android.checkjni=1 android.qemud=ttyS1 android.ndns=1″
emulator: argv[17] = “-m”
emulator: argv[18] = “96″
emulator: mapping ‘system’ NAND image to C:\DOCUME~1\LIZHON~1\LOCALS~1\Temp\\AndroidEmulator\TMP834.tmp
emulator: using ‘winaudio’ audio input backend
emulator: using ‘winaudio’ audio output backend
emulator: control console listening on port 5556, ADB on port 5557
emulator: sent ’0012host:emulator:5557′ to ADB server
emulator: ping program: E:\android_sdk\android-sdk-windows-1.6_r1\tools\ddms.bat
emulator: ping command: C:\WINDOWS\system32\cmd.exe /C “E:\android_sdk\android-sdk-windows-1.6_r1\tools\ddms.bat” ping emulator 1.11
(6) 使用- logcat 选项
emulator -logcat main -avd avd2
(7) 使用-trace选项
E:\android_sdk\android-sdk-windows-1.6_r1\tools>emulator -trace main(或events,或radio) -avd avd2
– When done tracing, exit the emulator. –
emulator: emulator window was out of view and was recentred
或者:
E:\android_sdk\android-sdk-windows-1.6_r1\tools>emulator -trace radio -trace main -trace radio -avd avd2
E:\android_sdk\android-sdk-windows-1.6_r1\tools>adb -help
Android Debug Bridge version 1.0.22
-d – directs command to the only connected USB device
returns an error if more than one USB device is present.
-e – directs command to the only running emulator.
returns an error if more than one emulator is running.
-s – directs command to the USB device or emulator with
the given serial number
-p
– simple product name like ‘sooner’, or
a relative/absolute path to a product
out directory like ‘out/target/product/sooner’.
If -p is not specified, the ANDROID_PRODUCT_OUT
environment variable is used, which must
be an absolute path.
devices – list all connected devices
device commands:
adb push – copy file/dir to device
adb pull – copy file/dir from device
adb sync [ ] – copy host->device only if changed
(see ‘adb help all’)
adb shell – run remote shell interactively
adb shell – run remote shell command
adb emu – run emulator console command
adb logcat [ ] – View device log
adb forward – forward socket connections
forward specs are one of:
tcp:
localabstract:
localreserved:
localfilesystem:
dev:
jdwp:
(remote only)
adb jdwp – list PIDs of processes hosting a JDWP transport
adb install [-l] [-r] – push this package file to the device and install it
(‘-l’ means forward-lock the app)
(‘-r’ means reinstall the app, keeping its data)
adb uninstall [-k]
– remove this app package from the device
(‘-k’ means keep the data and cache directories)
adb bugreport – return all information from the device
that should be included in a bug report.
adb help – show this help message
adb version – show version num
DATAOPTS:
(no option) – don’t touch the data partition
-w – wipe the data partition
-d – flash the data partition
scripting:
adb wait-for-device – block until device is online
adb start-server – ensure that there is a server running
adb kill-server – kill the server if it is running
adb get-state – prints: offline | bootloader | device
adb get-serialno – prints:
adb status-window – continuously print device status for a specified device
adb remount – remounts the /system partition on the device read-write
adb reboot [bootloader|recovery] – reboots the device, optionally into the bootloader or recovery program
adb root – restarts adb with root permissions
networking:
adb ppp [parameters] – Run PPP over USB.
Note: you should not automatically start a PPP connection. refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
[parameters] – Eg. defaultroute debug dump local notty usepeerdns
adb sync notes: adb sync [ ] can be interpreted in several ways:
– If is not specified, both /system and /data partitions will be updated.
- If it is “system” or “data”, only the corresponding partition
is updated.
14.2 scripting:
(1) start adb server
方法1: E:\android_sdk\android-sdk-windows-1.6_r1\tools>adb kill-server
E:\android_sdk\android-sdk-windows-1.6_r1\tools>adb start-server
* daemon not running. starting it now *
* daemon started successfully *
E:\android_sdk\android-sdk-windows-1.6_r1\tools>
(3) adb root
E:\android_sdk\android-sdk-windows-1.6_r1\tools>adb root
adbd is already running as root
adb reboot recovery
(4) adb reboot [android-sdk-windows-1.6_r1支持]
adb reboot bootloader(或 recovery)
说明:reboots the device, optionally into the bootloader or recovery program,可见,只针对真机,
所以,当运行此脚本时,模拟器就不能运行了。
另外,此脚本是从android-sdk-windows-1.6_r1开始支持的。
1.12.3 device commands:
(1) list all connected devices
E:\android_sdk\android-sdk-windows-1.6_r1\tools>adb devices
List of devices attached
emulator-5554 device
emulator-5556 device
(2) adb shell
开机:
E:\android_sdk\android-sdk-windows-1.6_r1\tools>adb shell
# ls
ls
sqlite_stmt_journals
cache
sdcard
etc
system
sys
sbin
proc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev
# cd data
cd data
# ls
ls
misc
local
data
app-private
app
property
anr
dalvik-cache
system
lost+found
(7) adb bugreport
列出了bug信息,see to bugreport.txt [ 点击查看 ]
13 关于编译
1.13.1 am:
adb install c:\NetScramble_1.1.apk
adb shell rm data/app/NetScramble_1.1.apk
am start -n net.xiashou.android/net.xiashou.android.HelloAndroid
# am start -a android.intent.action.VIEW -d http://www.xiashou.net
# am start -a android.intent.action.CALL -d tel:10086
# am start -a android.intent.action.VIEW geo:0,0?q=tianjin
# am start –n com.android.music/.MediaPlaybackActivity
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
// Instantiate an ImageView and define its properties
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.my_image);
i.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable’s dimensions
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
// Add the ImageView to the layout and set the layout as the content view
mLinearLayout.addView(i);
setContentView(mLinearLayout);
}
在其它情况下,你可能想把你的图片资源当作一个可绘制Drawable对象。为此,你可以这样做:
Resources res = mContext.getResources();
Drawable myImage = res.getDrawable(R.drawable.my_image);
注意: 每个你项目里的唯一资源只能维护一个状态,而无论你为它实例化了多少个不同对象。比如,如果你从相同的图像资源实例化两个可绘制对象,然后改变其中之一的属性(比如alpha),那它也将作用于另一个。所以当处理一个图片资源的多个实例时,你应该实施一个tween animation,而不是直接转换这个可绘制对象。
示例XML
下面的XML片断显示了如何添加一个可绘制资源到一个XML布局中的ImageView里(为了有趣些,添加一些红色渲染)。
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#55ff0000"
android:src="@drawable/my_image"/>
更多关于使用项目资源的信息,请阅读资源和资产Resources and Assets。
从资源XML中创建Creating from resource XML
到目前为止,你应该对Android用户界面User Interface的开发原理比较熟悉。因此,你应该了解在XML中定义对象所固有的能力和灵活性。这个理念从视图延伸到可绘制对象。如果你想创建一个可绘制(Drawable)对象,而它并不初始依赖于你代码中的变量或者用户交互,那么在XML里面定义它是个好的选择。即便你预期这个可绘制对象在用户使用你的应用程序时将会改变其属性,你也应该考虑在XML里面定义它,因为一旦被实例化后,你就可以修改它的属性。
一旦你在XML中定义了你的可绘制对象,把这个文件保存到你项目中的res/drawable/ 目录下。然后,通过传递资源ID参数调用Resources.getDrawable()获取并实例化这个对象。 (参见example below.)
任何支持inflate()方法的可绘制对象(Drawable)子类可以在XML里定义并由你的应用程序实例化。每个支持XML扩充的可绘制对象利用特定的XML属性来帮助定义对象属性(参见类参考了解这些属性)。查阅每个可绘制对象子类的类描述文档,以获知如何在XML中定义它。
例子Example
下面是一些定义了一个TransitionDrawable对象的XML语句:
博客分类: android
Android嵌入式.netBlog
三维图形3D with OpenGL
Android通过OpenGL API支持高性能三维图形-具体而言,是OpenGL ES API。
OpenGL ES是OpenGL的针对嵌入式设备的定制版本。OpenGL ES的各个版本不固定的对应于OpenGL主版本。Android当前支持OpenGL ES 1.0,对应于OpenGL 1.3。因此,如果你想得到的一个应用程序可以在桌面系统中用OpenGL 1.3来实现,那么它应该也有可能在Android实现。
Android提供的具体的API类似于J2ME JSR239 OpenGL ES API。但是,它也许不完全一致,因此需要注意这些差别。
使用API
下面是如何使用这些API的一个非常概要的描述:
1. 写一个自定义视图
2. 获取一个OpenGLContext句柄,这提供了OpenGL功能的访问入口。
3. 在你的视图的onDraw() 方法中,获取一个GL对象的句柄,并使用它的方法来执行GL的各种操作。
可以在com.android.samples.graphics.GLSurfaceViewActivity.java中找到这个应用模式(基于经典的GL ColorCube)的一个示例。
如何使用OpenGL写一个3D应用程序超出了本文范围,读者可以把这作为一个练习。
(译者注:你可以参考一个三维隧道程序,对应于Android SDK1.5的源代码链接如下:
http://download.csdn.net/source/1710418)
更多信息的链接Links to Additional Information
关于OpenGL ES的信息可以在http://www.khronos.org/opengles/上找到。
特别的,关于OpenGL ES 1.0的信息(包括一个详细的规格说明)可以在http://www.khronos.org/opengles/1_X/找到。
还有关于Android OpenGL ES implementations的文档。
最后,注意尽管Android确实包含对于OpenGL ES 1.1的基础支持,但是还不完整,目前最好不要依赖于它。
最重要的AppWidgetProvider 回调函数是onUpdated(), 因为它是在每个App Widget添加进宿主时被调用的(除非你使用一个配置活动)。如果你的App Widget 要接受任何用户交互事件,那么你需要在这个回调函数中注册事件处理器。如果你的App Widget不创建临时文件或数据库,或者执行其它需要清理的工作,那么onUpdated() 可能是你需要定义的唯一的回调函数。比如,如果你想要一个带一个按钮的App Widget,当点击时启动一个活动,你可以使用下面的AppWidgetProvider实现:
public class ExampleAppWidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, ExampleActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_layout);
views.setOnClickPendingIntent(R.id.button, pendingIntent);
同样的,活动必须在AppWidgetProviderInfo XML 文件中声明,通过android:configure属性(参见上面的添加AppWidgetProviderInfo元数据Adding the AppWidgetProviderInfo Metadata)。比如,配置活动可以声明如下:
...
android:configure="com.example.android.ExampleAppWidgetConfigure"
... >
public class androidId extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fetch_status();
}
程序的代码非常简单,SimpleIntentTest类的源代码如下:
package com.tope.samples.intent.simple;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class SimpleIntentTest extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button startBtn = (Button)findViewById(R.id.start_activity);
startBtn.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.start_activity:
Intent intent = new Intent(this, TestActivity.class);
startActivity(intent);
break;
default:
break;
}
}
}
上面的代码中,主要是为“Start activity”按钮添加了OnClickListener,使得按钮被点击时执行onClick()方法,onClick()方法中则利用了Intent机制,来启动TestActivity,关键的代码是下面这两行:
Intent intent = new Intent(this, TestActivity.class);
startActivity(intent);
这里定义Intent对象时所用到的是Intent的构造函数之一:
Intent(Context packageContext, Class> cls)
两个参数分别指定Context和Class,由于将Class设置为TestActivity.class,这样便显式的指定了TestActivity类作为该Intent的接收者,通过后面的startActivity()方法便可启动TestActivity。
TestActivity的代码更为简单(定义TestActivity类需要新建TestActivity.java文件,如果你是一个初学者,你需要学会如何在Eclipse或其他开发环境下添加一个新的类,本书不作详述,请参考其他文档),如下所示:
package com.tope.samples.intent.simple;
import android.app.Activity;
import android.os.Bundle;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity);
}
}
可见TestActivity仅仅是调用setContentView来显示test_activity.xml中的内容而已。对于test_activity.xml及本例中所用到其他xml文件这里不作多余说明,读者练习时可自行参考本书所附光盘中的源代码。
如果我们仅仅是做上面的一些工作,还不能达到利用SimpleIntentTest启动TestActivity的目的。事实上,这样做会出现下面的Exception,导致程序退出。以下是利用logcat工具记录的log信息(省略了后半部分):
I/ActivityManager( 569): Displayed activity com.tope.samples/.SimpleIntentTest: 3018 ms
I/ActivityManager( 569): Starting activity: Intent { comp={com.tope.samples/com.tope.samples.TestActivity} }
D/AndroidRuntime( 932): Shutting down VM
W/dalvikvm( 932): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
E/AndroidRuntime( 932): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 932): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.tope.samples/com.tope.samples.TestActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 932): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1480)
E/AndroidRuntime( 932): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1454)
E/AndroidRuntime( 932): at android.app.Activity.startActivityForResult(Activity.java:2656)
E/AndroidRuntime( 932): at android.app.Activity.startActivity(Activity.java:2700)
E/AndroidRuntime( 932): at com.tope.samples.SimpleIntentTest.onClick(SimpleIntentTest.java:24)
…
Android Intent机制实例详解三
从这些log中我们可以看到点击按钮后startActivity的调用过程,主要的原因是:“android.content.ActivityNotFoundException: Unable to find explicit activity class {com.tope.samples/com.tope.samples.TestActivity}; have you declared this activity in your AndroidManifest.xml?”
从这些log我们可以看到原因是找不到TestActivity这个Activity,并且log中还给出了提示:你是否在AndroidManifest.xml中声明了这个Activity?解决问题的方法也就是按照提示在AndroidManifest.xml中增加TestActivity的声明,如下所示,注意粗体字部分:
完成这个修改后再重新运行该程序,就一切都正常了。
从AndroidManifest.xml修改的过程我们可以体会到,Intent机制即使在程序内部且显式指定接收者,也还是需要在AndroidManifest.xml中声明TestActivity。这个过程并不像一个简单的函数调用,显式的Intent也同样经过了Android应用程序框架所提供的支持,从满足条件的Activity中进行选择,如果不在AndroidManifest.xml中进行声明,则Android应用程序框架找不到所需要的Activity。
请读者通过我们的示例来逐步理解AndroidManifest.xml在这个过程中所扮演的角色,这样有利于理解Intent的作用,及后面的Intent Filter。当然,这个例子仅仅是开始,且看下文分解。
² 不同应用程序之间的Activity切换
上面的例子我们所做的是在同一应用程序中进行Activity的切换,那么在不同的应用程序中,是否也能这么做呢,答案是肯定的,不过对应的代码要稍作修改。本例中我们需要两个应用程序,可利用上例中的SimpleIntentTest作为其中之一,另外还需要写一个新的程序,来调用SimpleIntentTest应用程序中的TestActivity。
我们新建程序CrossIntentTest(注意不是新建一个类,如果是Eclipse环境,选择File->New->Project新建工程),其中只有一个Activity,其源代码与SimpleIntentTest.java类似:
package com.tope.samples.intent.cross;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class CrossIntentTest extends Activity
implements View.OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button startBtn = (Button)findViewById(R.id.start_activity);
startBtn.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.start_activity:
Intent intent = new Intent();
intent.setClassName(“com.tope.samples.intent.simple”,
“com.tope.samples.intent.simple.TestActivity”);
startActivity(intent);
break;
default:
break;
}
}
}
注意比较它与SimpleIntentTest的不同之处主要在于初始化Intent对象的过程:
Intent intent = new Intent();
intent.setClassName(“com.tope.samples.intent.simple”,
“com.tope.samples.intent.simple.TestActivity”);
startActivity(intent);
Android Intent机制实例详解四
package com.tope.samples.intent.simple;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class SimpleIntentTest extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button startBtn = (Button)findViewById(R.id.start_activity);
startBtn.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.start_activity:
Intent intent = new Intent(this, TestActivity.class);
startActivity(intent);
break;
default:
break;
}
}
}
上面的代码中,主要是为“Start activity”按钮添加了OnClickListener,使得按钮被点击时执行onClick()方法,onClick()方法中则利用了Intent机制,来启动TestActivity,关键的代码是下面这两行:
Intent intent = new Intent(this, TestActivity.class);
startActivity(intent);
这里定义Intent对象时所用到的是Intent的构造函数之一:
Intent(Context packageContext, Class> cls)
两个参数分别指定Context和Class,由于将Class设置为TestActivity.class,这样便显式的指定了TestActivity类作为该Intent的接收者,通过后面的startActivity()方法便可启动TestActivity。
TestActivity的代码更为简单(定义TestActivity类需要新建TestActivity.java文件,如果你是一个初学者,你需要学会如何在Eclipse或其他开发环境下添加一个新的类,本书不作详述,请参考其他文档),如下所示:
package com.tope.samples.intent.simple;
import android.app.Activity;
import android.os.Bundle;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity);
}
}
可见TestActivity仅仅是调用setContentView来显示test_activity.xml中的内容而已。对于test_activity.xml及本例中所用到其他xml文件这里不作多余说明,读者练习时可自行参考本书所附光盘中的源代码。
如果我们仅仅是做上面的一些工作,还不能达到利用SimpleIntentTest启动TestActivity的目的。事实上,这样做会出现下面的Exception,导致程序退出。以下是利用logcat工具记录的log信息(省略了后半部分):
I/ActivityManager( 569): Displayed activity com.tope.samples/.SimpleIntentTest: 3018 ms
I/ActivityManager( 569): Starting activity: Intent { comp={com.tope.samples/com.tope.samples.TestActivity} }
D/AndroidRuntime( 932): Shutting down VM
W/dalvikvm( 932): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
E/AndroidRuntime( 932): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 932): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.tope.samples/com.tope.samples.TestActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 932): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1480)
E/AndroidRuntime( 932): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1454)
E/AndroidRuntime( 932): at android.app.Activity.startActivityForResult(Activity.java:2656)
E/AndroidRuntime( 932): at android.app.Activity.startActivity(Activity.java:2700)
E/AndroidRuntime( 932): at com.tope.samples.SimpleIntentTest.onClick(SimpleIntentTest.java:24)
…
Android Intent机制实例详解五
从这些log中我们可以看到点击按钮后startActivity的调用过程,主要的原因是:“android.content.ActivityNotFoundException: Unable to find explicit activity class {com.tope.samples/com.tope.samples.TestActivity}; have you declared this activity in your AndroidManifest.xml?”
从这些log我们可以看到原因是找不到TestActivity这个Activity,并且log中还给出了提示:你是否在AndroidManifest.xml中声明了这个Activity?解决问题的方法也就是按照提示在AndroidManifest.xml中增加TestActivity的声明,如下所示,注意粗体字部分:
public class Welcome extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
// TODO
break;
case R.id.help:
// TODO
break;
case R.id.save:
// TODO
break;
case R.id.exit:
// TODO
break;
}
return true;
}
}
Intents and Intent Filters
Intent Objects Intent对象
Intent Resolution Intent解析
Intent filters
Filters and security Filter和安全
Common cases 常见情况
Using intent matching 使用intent匹配
Note Pad Example 例子:记事本