編輯:高級開發
Activity performLaunchActivity(ActivityClIEntRecord r, Intent customIntent) 此類負責創建Activity實例和一些information。並回調一些Activity 的回調函數 onXXX().
其中調用了 activity.attach(*******)。
Java代碼
final void attach(Context context, ActivityThread aThread,
Instrumentation instr, IBinder token, int ident,
Application application, Intent intent, ActivityInfo info,
CharSequence title, Activity parent, String id,
Object lastNonConfigurationInstance,
HashMap lastNonConfigurationChildInstances,
Configuration config) {
attachBaseContext(context);
mWindow = PolicyManager.makeNewWindow(this);
mWindow.setCallback(this);
if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
mWindow.setSoftInputMode(info.softInputMode);
}
mUiThread = Thread.currentThread();
mMainThread = aThread;
mInstrumentation = instr;
mToken = token;
mIdent = ident;
mApplication = application;
mIntent = intent;
mComponent = intent.getComponent();
MactivityInfo = info;
mTitle = title;
mParent = parent;
mEmbeddedID = id;
mLastNonConfigurationInstance = lastNonConfigurationInstance;
mLastNonConfigurationChildInstances = lastNonConfigurationChildInstances;
mWindow.setWindowManager(null, mToken, mComponent.flattenToString());
if (mParent != null) {
mWindow.setContainer(mParent.getWindow());
}
mWindowManager = mWindow.getWindowManager();
mCurrentConfig = config;
}
final void attach(Context context, ActivityThread aThread,
Instrumentation instr, IBinder token, int ident,
接上頁
Application application, Intent intent, ActivityInfo info,
CharSequence title, Activity parent, String id,
Object lastNonConfigurationInstance,
HashMap lastNonConfigurationChildInstances,
Configuration config) {
attachBaseContext(context);
mWindow = PolicyManager.makeNewWindow(this);
mWindow.setCallback(this);
if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
mWindow.setSoftInputMode(info.softInputMode);
}
mUiThread = Thread.currentThread();
mMainThread = aThread;
mInstrumentation = instr;
mToken = token;
mIdent = ident;
mApplication = application;
mIntent = intent;
mComponent = intent.getComponent();
MactivityInfo = info;
mTitle = title;
mParent = parent;
mEmbeddedID = id;
mLastNonConfigurationInstance = lastNonConfigurationInstance;
mLastNonConfigurationChildInstances = lastNonConfigurationChildInstances;
mWindow.setWindowManager(null, mToken, mComponent.flattenToString());
if (mParent != null) {
mWindow.setContainer(mParent.getWindow());
}
mWindowManager = mWindow.getWindowManager();
mCurrentConfig = config;
}
創建Window ,創建的是PhoneWindow
Java代碼
private static final String POLICY_IMPL_CLASS_NAME =
"com.android.internal.policy.impl.Policy";
static {
// Pull in the actual implementation of the policy at run-time
try {
Class policyClass = Class.forName(POLICY_IMPL_CLASS_NAME);
sPolicy = (IPolicy)policyClass.newInstance();
} catch (ClassNotFoundException ex) {
throw new RuntimeException(
POLICY_IMPL_CLASS_NAME + " could not be loaded", ex);
接上頁
} catch (InstantiationException ex) {
throw new RuntimeException(
POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);
} catch (IllegalAccessException ex) {
throw new RuntimeException(
POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);
}
}
上面代碼是靜態模塊,類被加載時就被執行。
public static Window makeNewWindow(Context context) {
return sPolicy.makeNewWindow(context);
}
public PhoneWindow makeNewWindow(Context context) {
return new PhoneWindow(context);
}
private static final String POLICY_IMPL_CLASS_NAME =
"com.android.internal.policy.impl.Policy";
static {
// Pull in the actual implementation of the policy at run-time
try {
Class policyClass = Class.forName(POLICY_IMPL_CLASS_NAME);
sPolicy = (IPolicy)policyClass.newInstance();
} catch (ClassNotFoundException ex) {
throw new RuntimeException(
POLICY_IMPL_CLASS_NAME + " could not be loaded", ex);
} catch (InstantiationException ex) {
throw new RuntimeException(
POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);
} catch (IllegalAccessException ex) {
throw new RuntimeException(
POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);
}
}
上面代碼是靜態模塊,類被加載時就被執行。
public static Window makeNewWindow(Context context) {
return sPolicy.makeNewWindow(context);
}
public PhoneWindow makeNewWindow(Context context) {
return new PhoneWindow(context);
}
下面是創建WindowManger
Java代碼
mWindow.setWindowManager(null, mToken, mComponent.flattenToString());
public void setWindowManager(WindowManager wm,
接上頁
IBinder aPPToken, String appName) {
mAppToken = aPPToken;
mAppName = appName;
if (wm == null) {
wm = WindowManagerImpl.getDefault();
}
mWindowManager = new LocalWindowManager(wm);
}
mWindow.setWindowManager(null, mToken, mComponent.flattenToString());
public void setWindowManager(WindowManager wm,
IBinder aPPToken, String appName) {
mAppToken = aPPToken;
mAppName = appName;
if (wm == null) {
wm = WindowManagerImpl.getDefault();
}
mWindowManager = new LocalWindowManager(wm);
}
wm = WindowManagerImpl.getDefault();是返回一個默認的WindowManagerImpl 的靜態實例,在android系統中的所有應用程序,都共用一個WindowManagerImpl實例。
Window 被創建的時候,會執行如下代碼來生成Window Attrivute
Java代碼
private final WindowManager.LayoutParams mWindowAttributes =
new WindowManager.LayoutParams();
private final WindowManager.LayoutParams mWindowAttributes =
new WindowManager.LayoutParams();
下面是更改此屬性:
Java代碼
/**
* Specify custom window attributes. PLEASE NOTE: the
* layout params you give here should generally be from values previously
* retrIEved with {@link #getAttributes()}; you probably do not want to
* blindly create and apply your own, since this will blow away any values
* set by the framework that you are not interested in.
*
* @param a The new window attributes, which will completely override any
* current values.
*/
public void setAttributes(WindowManager.LayoutParams a) {
mWindowAttributes.copyFrom(a);
if (mCallback != null) {
mCallback.onWindowAttributesChanged(mWindowAttributes);
接上頁
}
}
/**
* Specify custom window attributes. PLEASE NOTE: the
* layout params you give here should generally be from values previously
* retrIEved with {@link #getAttributes()}; you probably do not want to
* blindly create and apply your own, since this will blow away any values
* set by the framework that you are not interested in.
*
* @param a The new window attributes, which will completely override any
* current values.
*/
public void setAttributes(WindowManager.LayoutParams a) {
mWindowAttributes.copyFrom(a);
if (mCallback != null) {
mCallback.onWindowAttributesChanged(mWindowAttributes);
}
}
要更改mWindowAttributes此屬性,只能用此方法,並回調。
android模擬器的重點就是商業應用,Google采用了一些手法來繞過這問題,建築在android之上的硬件驅動和應用程序,要求開源社區為它做貢獻,卻又不願提供回報。
在android SDK系統中已經沒有了JDK,自然也無法運行JUnit,但是這並不能阻止我們利用JUnit來編寫單元測試,下面的文章進行詳細說明下android SD
2009年4月27日,谷歌正式發布android 1.5 SDK;T-Mobile的G1英國手機用戶今天開始可以將其android升級至1.5版本,這一版本中新增了很多
Dashboard,一種專門針對入口界面設計的應用程序,Dashboard (為儀表板之意)原來是蘋果公司 Mac OS X v10.4 Tiger 作業系統中的應用程