Service

service的两种启动方法(区别,和包括关闭条件)

remote service and local service (在不同的进程中,远程的需要通过messenger and handler 来实现cross thread UI operation)

在androidmainfast.xml中注册时有与没有filter的区别。或者说是对service的访问进行控制

通过bind方法启动的service在权重较高,在内存不容易被kill.而start方式可以通过onstartcommand()方法的返回值来设置低内存时候的处理方式。

activity

每个拥有id的view在内存不够被kill的时候都可以自动保存自己的状态。OnIntanceState()

如果想持久化一些数据推荐在onPause()中进行

task:一个task就对应一个stack。这就要关于activity的四种模式default,single of top,single task ,single instance。可以通过在mainfast.xml中设置也可以在用Intent打开时候指定,但这两种方式不能完全代替。如果同时设置,以intent中的设置优先。

 single task and single instance区别:在同一时间都只能拥有一个实例。区别在于single instance 在它所在的tack中只一个activity。任何时候都只有一个,如果在instance的activity中打开一个activity,那么这个activity在另一个task中。


1、在android横竖屏切换时,系统会自动调用onSaveInstanceState()方法,而在之后会调用onCreate()方法,此时create中的bundle不为空,之后在onStart()方法执行后还会调用onRestoreInstanceState(),原因是在有些情况onCrteate后才能从之前状态获取数据.

2、android app 是否支持大屏与其它是否使用大屏的layout没有关系,当设备为大屏幕时,就会去查找大屏幕的layout。

3、Local service 不用Messager通讯,在绑定时可以用ibinder直接拿到service类型,然后直接操作。remote service 我们拿不到service类型,所以通讯只能用messenger来执行。remote service多用单个线程

4、start service和bindservice 的区别多个程序共用一个service时用bindservice,这样当一个程序结束后,调用unbind不会对service有什么太大的影响,但如果是start的话就还要调用stop方法,而只要调用一次service就挂了。还可以这两种混合用

5 To query a content provider, you can use either the ContentResolver.query()  method or the Activity.managedQuery() method

6 intent 中的<data>更详细请看http://developer.android.com/guide/topics/intents/intents-filters.html中的data

<data android:host="string"
      android:mimeType="string"
      android:path="string"
      android:pathPattern="string"
      android:pathPrefix="string"
      android:port="string"
      android:scheme="string" />

它是用来检测打开此activity 的intent中uri所指向的数据的类型如果数据不符合,就不能打开此activity,如:

传送SMS/MMS

1. //调用短信程序 
   2. Intent it = new Intent(Intent.ACTION_VIEW, uri);  
   3. it.putExtra("sms_body", "The SMS text");   
   4. it.setType("vnd.android-dir/mms-sms");//这就是data中mimeType所指向的数据  
   5. startActivity(it);

播放多媒体

Uri uri = Uri.parse("file:///sdcard/song.mp3");  
       Intent it = new Intent(Intent.ACTION_VIEW, uri);  
       it.setType("audio/mp3");  
       startActivity(it);

 

The data test compares both the URI and the data type in the Intent object to a URI and data type specified in the filter. The rules are as follows:

  1. An Intent object that contains neither a URI nor a data type passes the test only if the filter likewise does not specify any URIs or data types.
  2. An Intent object that contains a URI but no data type (and a type cannot be inferred from the URI) passes the test only if its URI matches a URI in the filter and the filter likewise does not specify a type. This will be the case only for URIs like mailto: and tel: that do not refer to actual data.
  3. An Intent object that contains a data type but not a URI passes the test only if the filter lists the same data type and similarly does not specify a URI.
  4. An Intent object that contains both a URI and a data type (or a data type can be inferred from the URI) passes the data type part of the test only if its type matches a type listed in the filter. It passes the URI part of the test either if its URI matches a URI in the filter or if it has a content: or file: URI and the filter does not specify a URI. In other words, a component is presumed to support content: and file: data if its filter lists only a data type.

 Thread::::::::

1 当需要跨线程与UI进行交互时,一共提供3种方法:

 简单的操作

  • Activity.runOnUiThread(Runnable)
  • View.post(Runnable)
  • View.postDelayed(Runnable, long)

For example, you can fix the above code by using the View.post(Runnable) method:

public void onClick(View v) {
    new Thread(new Runnable() {
        public void run() {
            final Bitmap bitmap = loadImageFromNetwork("http://example.com/image.png");
            mImageView.post(new Runnable() {
                public void run() {
                    mImageView.setImageBitmap(bitmap);
                }
            });
        }
    }).start();
}

较复杂的操作

To handle more complex interactions with a worker thread, you might consider using a Handler in your worker thread, to process messages delivered from the UI thread. Perhaps the best solution, though, is to extend the AsyncTask class, which simplifies the execution of worker thread tasks that need to interact with the UI.