imsdroid啓動Activity的方式很獨特

  近來在調試imsdroid,想限制轉屏。結果發現常用的辦法無效。這是爲什麼呢?後來研究了一下啓動Activity的代碼,有點獨特。具體代碼是:

	@Override
	public boolean show(Class<? extends Activity> cls, String id) {
		final Main mainActivity = (Main)Engine.getInstance().getMainActivity();
		
		String screen_id = (id == null) ? cls.getCanonicalName() : id;
		Intent intent = new Intent(mainActivity, cls);
		intent.putExtra("id", screen_id);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		final Window window = mainActivity.getLocalActivityManager().startActivity(screen_id, intent);
		if(window != null){
			View view = mainActivity.getLocalActivityManager().startActivity(screen_id, intent).getDecorView();
			
			LinearLayout layout = (LinearLayout) mainActivity.findViewById(R.id.main_linearLayout_principal);
			layout.removeAllViews();
			layout.addView(view, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
			
			// add to stack
			this.mLastScreens[(++this.mLastScreensIndex % this.mLastScreens.length)] = screen_id;
			this.mLastScreensIndex %= this.mLastScreens.length;
			return true;
		}
		return false;
	}

  初步分析來說,相當於把一個Activity作爲容器,然後把另外一個Activity放進去。也就是說,要想設置,就必須在主Activity中(或者在Manifest.xml)。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章