HTML/JavaScript小工具

HTML/JavaScript小工具

2012年12月18日 星期二

IPC名詞解釋(簡單版)


轉貼文章用來記綠

Remote Procedure Call

謂的procedure call或稱為function call,是一種廣泛運用於programming的流程控制。運作
方式是將控制權從一個process的某部份轉移到另一個process,進行某些運算之後,再把
控制權歸還給呼叫這個procedure的呼叫者。在進行procedure call時,caller會傳送一些參數
給被呼叫者;而被呼叫者也會將一個或多個傳回值傳給呼叫者。

一般而言,若呼叫者與被呼叫者是在同一個系統內,我們稱為local procedure call
若呼叫者與被呼叫者處於不同的系統,也就是說,呼叫者在local端透過網路來呼叫remote端
的procedure,我們稱為remote procedure call(簡稱為RPC),中文翻譯為遠端程序呼叫



inter-Process Communication IPC (Process 之間溝通)
在Android中是使用Binder來通訊!

Android Thread的限制!


  1. Do not block the UI thread 
  2. Do not access the Android UI toolkit from outside the UI thread

由第二點得知只能在UI Thread控制UI所以~~~Android提供了以下簡單方法:
這些方法可以讓你在另外一個執行緒控制UI

但是程式中過多這樣的寫法是不好的,於是發展了一個AsyncTask ,可將UI與背景想做的事分開,如此程式維護上比較清晰


要使用AsyncTask  必須Extends AsyncTask 做法如下:已下轉貼Android API低阿~


public void onClick(View v) {
    //你要執行時呼叫execute
    new DownloadImageTask().execute("http://example.com/image.png");
}

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    /** The system calls this to perform work in a worker thread and
      * delivers it the parameters given to AsyncTask.execute() */
    protected Bitmap doInBackground(String... urls) {
        //這裡做你想在背景做的事,如由網錄下在圖檔等...
return loadImageFromNetwork(urls[0]);
    }
    
    /** The system calls this to perform work in the UI thread and delivers
      * the result from doInBackground() */
    protected void onPostExecute(Bitmap result) {
//這裡做在UI裡顯示什麼東西!如將網路抓來的圖片顯示在ImageView中
        mImageView.setImageBitmap(result);
    }
}
其他:


微蝦咪要用Service!!

在Android內
Service跟Threds用法看起來很像喔!!~~
但他們是2個不同的東東!!

1 Service有自己的生命週期
2 使用Service時,會進入Service process ,這樣當Android自動刪除process會將他列入權重
3 Service可以使用ADIL!

以上...這只是筆記!!~~提供參考~~GOGO~~

Android Process 刪除順序


  1. Foreground process
    A process that is required for what the user is currently doing. A process is considered to be in the foreground if any of the following conditions are true:
    Generally, only a few foreground processes exist at any given time. They are killed only as a last resort—if memory is so low that they cannot all continue to run. Generally, at that point, the device has reached a memory paging state, so killing some foreground processes is required to keep the user interface responsive.
  2. Visible process
    A process that doesn't have any foreground components, but still can affect what the user sees on screen. A process is considered to be visible if either of the following conditions are true:
    • It hosts an Activity that is not in the foreground, but is still visible to the user (its onPause() method has been called). This might occur, for example, if the foreground activity started a dialog, which allows the previous activity to be seen behind it.
    • It hosts a Service that's bound to a visible (or foreground) activity.
    A visible process is considered extremely important and will not be killed unless doing so is required to keep all foreground processes running.
  3. Service process
    A process that is running a service that has been started with the startService() method and does not fall into either of the two higher categories. Although service processes are not directly tied to anything the user sees, they are generally doing things that the user cares about (such as playing music in the background or downloading data on the network), so the system keeps them running unless there's not enough memory to retain them along with all foreground and visible processes.
  4. Background process
    A process holding an activity that's not currently visible to the user (the activity's onStop() method has been called). These processes have no direct impact on the user experience, and the system can kill them at any time to reclaim memory for a foreground, visible, or service process. Usually there are many background processes running, so they are kept in an LRU (least recently used) list to ensure that the process with the activity that was most recently seen by the user is the last to be killed. If an activity implements its lifecycle methods correctly, and saves its current state, killing its process will not have a visible effect on the user experience, because when the user navigates back to the activity, the activity restores all of its visible state. See the Activities document for information about saving and restoring state.
  5. Empty process
    A process that doesn't hold any active application components. The only reason to keep this kind of process alive is for caching purposes, to improve startup time the next time a component needs to run in it. The system often kills these processes in order to balance overall system resources between process caches and the underlying kernel caches.

2012年12月11日 星期二

慢慢讀Android API系列之 --Context-1

慢慢讀Android API系列之 --Context-1

挑選了一些我覺得比較重要的方法或一些參數


ACCESSIBILITY_SERVICE-- 輔助服務(類似無障礙App)
AUDIO_SERVICE--跟聲音與震動有關的服務
CLIPBOARD_SERVICE --可取得剪貼簿管理
DEVICE_POLICY_SERVICE 可管理和操作设备的API
DOWNLOAD_SERVICE--可取得下載服務

DROPBOX_SERVICE --DropBoxManager 是 Android 在 Froyo(API level 8) 引入的用来持续化存储系统数据的机制, 主要用于记录 Android 运行过程中, 内核, 系统进程, 用户进程等出现严重问题时的 log, 可以认为这是一个可持续存储的系统级别的 logcat.我们可以通过用参数 DROPBOX_SERVICE 调用 getSystemService(String) 来获得这个服务, 并查询出所有存储在 DropBoxManager 里的系统错误记录.
INPUT_METHOD_SERVICE--可取得管理軟體鍵盤的服務
KEYGUARD_SERVICE--鍵盤鎖管理
LOCATION_SERVICE--跟GPS比較有關係低
MEDIA_ROUTER_SERVICE-->JELLY才有低

MODE_APPEND--> openFileOutput會用到的參數
NOTIFICATION_SERVICE-->傳遞訊息的服務
POWER_SERVICE-->取得管理電源的服務
STORAGE_SERVICE-->可以管理OOB文檔(有機會研究一下)
TELEPHONY_SERVICE-->電話管理服務(有誰打來啦等等資訊)
UI_MODE_SERVICE-->Android设备的夜间模式和行车模式


USB_SERVICE-->3.1之後才可用的方法



以上這些SERVICE之後會慢慢低介紹一下!!!







下面這些方法的用法之後也會介紹
 createPackageContext
getSystemService(String)