创建手机模拟器时:
屏幕分辨率
HVGA:320×480
QVGA:240x320
WQVGA400:240X400
WQVAG432:240X432
WVGA800: 480X800
WVGA854: 480X854
WebView,WebViewClient,WebChromeClient的关系
在WebView的设计中,不是什么事都要WebView类干的,有些杂事是分给其他人的,这样WebView专心干好自己的解析、渲染工作就行了。WebViewClient就是帮助WebView处理各种通知、请求事件的,具体来说包括:
onLoadResource
onPageStart
onPageFinish
onReceiveError
onReceivedHttpAuthRequest
WebChromeClient是辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等
onCloseWindow(关闭WebView)
onCreateWindow()
onJsAlert (WebView上alert是弹不出来东西的,需要定制你的WebChromeClient处理弹出)
onJsPrompt
onJsConfirm
onProgressChanged
onReceivedIcon
onReceivedTitle
安装Android应用
<!-- 安装程序权限 -->
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
代码:
private EditText filenameText;//在sd卡中的路径
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button=(Button)this.findViewById(R.id.button);
filenameText=(EditText) this.findViewById(R.id.filename);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//标志,代表我要启动一个新的任务
//action=android.content.Intent.ACTION_VIEW
//category=android.intent.category.DEFAULT
//data:type=application/vnd.android.package-archive
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri data=Uri.fromFile(new File(Environment.getExternalStorageDirectory(),filenameText.getText().toString()));
intent.setDataAndType(data,"application/vnd.android.package-archive");
startActivity(intent);
}else {
Toast.makeText(InstallActivity.this,"SD卡不存在",Toast.LENGTH_LONG).show();
}
}
});
}
startManagingCursor(Cursor cursor)这个方法告诉活动应该根据该活动的生命周期来管理光标的生命周期。例如,当活动被暂停时,它将自动停用光标,然后在活动重启时重新查询该光标。当活动终止时,所有托管的光标也将关闭。
stopManagingCursor(Cursor cursor)这个是停止根据该活动的生命周期来管理光标的生命周期。
在Android安全模式中,一个应用程序编写的文件无法被其他任何应用程序所读写。每个程序都有自己的Linux用户ID和数据目录(/data/data/包名),以及其受保护的内存空间。Android程序可通过下面两种方式进行彼此间的通信:
方式一 IPC(Inter-Process Communication,进程间通信):一个进程使用AIDL(Android Inteerface Definition Language,接口定义语言)和IBinder接口声明一个任意的API。调用该API时,将在进程间安全且有效地对参数进行编组。这个技术用于对后台Service线程进行远程过程调用。
方式二 ContentProvider:进程在系统中将它们本身注册为某些数据类型的提供者。详细见:http://justsee.iteye.com/blog/936612
@Override
public Cursor query(Uri uri, String[] projection,
String selection, String[] selectionArgs, String orderBy) {
if (uriMatcher.match(uri) == EVENTS_ID) {
long id = Long.parseLong(uri.getPathSegments().get(1));
selection = appendRowId(selection, id);
}
// Get the database and run the query
SQLiteDatabase db = events.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, projection, selection,
selectionArgs, null, null, orderBy);
// Tell the cursor what uri to watch, so it knows when its source data changes
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
这里要注意,这个观察者模式是从sdk level 1就有的,也就是说,cursor可以接收通知来感知content provider数据变化,但是不能做到异步刷新界面。这次1.6Loader机制通过官方支持实现了这个功能。
private String appendRowId(String selection, long id) {
return _ID + "=" + id
+ (!TextUtils.isEmpty(selection)
? " AND (" + selection + ')'
: "");
}
组件(Service,Activity,BoardcastReceiver,ContentProvider)运行在应用程序进程的主线程中,所以组件不会阻塞其他组件和用户界面。
一旦需要通过这4种组件完成请求,Android会首先确认该组件所在的进程是否运行,如果没有运行,Android将启动进程,同时确认被请求组件的实例是否存在,否则将创建一个新的组件实例。
findViewById(int id)原理:
View android.app.Activity.findViewById(int id),其中的id必须是之前已经设置为当前Activity主界面的XML布局文件中某个标签的id,否则findViewById会因为找不到View对象而返回null。
例如:
setContentView(R.layout.main);
fromSpinner = (Spinner) findViewById(R.id.from_language);
当需要引用其他XML布局文件中的View的时候,首先要根据XML的布局文件的设置构造View对象,然后View android.view.View.findViewById(int id)。
例如:
LinearLayout mainLayout=(LinearLayout)getLayoutflater().inflate(R.layout.main , null);
TextView tv=(TextView)mainLayout.findViewById(R.id.textview1);
tv.setText(R.string.hello);
setContentView(mainLayout);