QQ游戏哪几款是自己研发一款手机 投资的

口令:YFVB
123456789101112131415
123456789101112131415关于QQ游戏大厅的架构小弟我也想说几句 - 移动开发当前位置:& &&&关于QQ游戏大厅的架构小弟我也想说几句关于QQ游戏大厅的架构小弟我也想说几句&&网友分享于:&&浏览:9次关于QQ游戏大厅的架构我也想说几句先抛砖引玉一下,接个例子说明,现在的例子是要实现:
一个***的apk里面的一个activity A要去调用一个放在sd卡上的没***的apk里面的activity B,点返回键又回到Activity A,而不是直接退出。
ok,我这里已经有现成的方法了,先上代码:
主动去加载的SD上类的activity
import java.lang.reflect.C
import java.lang.reflect.M
import android.app.A
import android.content.I
import android.content.pm.PackageI
import android.os.B
import android.util.L
import android.view.KeyE
import android.view.V
import android.view.View.OnClickL
import android.widget.B
import android.widget.T
import dalvik.system.DexClassL
public class MainActivity
extends Activity {
private static final String TAG = &MainActivity&;
private boolean isJumped =
private Class localC
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
isJumped =
Bundle paramBundle = new Bundle();
paramBundle.putBoolean(&KEY_START_FROM_OTHER_ACTIVITY&, true);
String dexpath = &/mnt/sdcard/ToolA.apk&;
String dexoutputpath = &/mnt/sdcard/&;
LoadAPK(paramBundle, dexpath, dexoutputpath);
protected void onDestroy() {
super.onDestroy();
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (isJumped) {
Bundle paramBundle = new Bundle();
paramBundle.putBoolean(&KEY_START_FROM_OTHER_ACTIVITY&, true);
closeAPK(paramBundle);
isJumped =
return super.onKeyDown(keyCode, event);
public void LoadAPK(Bundle paramBundle, String dexpath, String dexoutputpath) {
ClassLoader localClassLoader = ClassLoader.getSystemClassLoader();
DexClassLoader localDexClassLoader =
new DexClassLoader(dexpath, dexoutputpath, null, localClassLoader);
PackageInfo plocalObject = getPackageManager().getPackageArchiveInfo(dexpath, 1);
if ((plocalObject.activities != null) && (plocalObject.activities.length & 0)) {
String activityname = plocalObject.activities[0].
Log.d(TAG, &activityname = & + activityname);
localClass = localDexClassLoader.loadClass(activityname);
Constructor localConstructor = localClass.getConstructor(new Class[] {});
instance = localConstructor.newInstance(new Object[] {});
Log.d(TAG, &instance = & + instance);
Method localMethodSetActivity =
localClass.getDeclaredMethod(&setActivity&, new Class[] {Activity.class});
localMethodSetActivity.setAccessible(true);
localMethodSetActivity.invoke(instance, new Object[] {this});
Method methodonCreate = localClass.getDeclaredMethod(&onCreate&, new Class[] {Bundle.class});
methodonCreate.setAccessible(true);
methodonCreate.invoke(instance, new Object[] {paramBundle});
catch (Exception ex) {
ex.printStackTrace();
public void closeAPK(Bundle paramBundle) {
Method methodonCreate = localClass.getDeclaredMethod(&onGoBack&);
methodonCreate.setAccessible(true);
methodonCreate.invoke(instance);
} catch (Exception ex) {
ex.printStackTrace();
另外一个是sd卡上待加载的activity:
package mobi.thinkchange.android.
import android.app.A
import android.os.B
import android.util.L
import android.view.KeyE
import android.widget.T
public class ToolAActivity
extends Activity {
private static final String TAG = &ToolAActivity&;
private Activity otherA
public void onCreate(Bundle savedInstanceState) {
boolean b =
if (savedInstanceState != null) {
b = savedInstanceState.getBoolean(&KEY_START_FROM_OTHER_ACTIVITY&, false);
this.otherActivity.setContentView(new TBSurfaceView(this.otherActivity));
super.onCreate(savedInstanceState);
setContentView(new TBSurfaceView(this));
public void setActivity(Activity paramActivity) {
Log.d(TAG, &setActivity...& + paramActivity);
this.otherActivity = paramA
public void onGoBack() {
otherActivity.setContentView(R.layout.main);
上面是实现我说的例子最核心的两个类,全部代码详见:http://download.csdn.net/detail/androidzhaoxiaogang/4903804
(代码只是片段,如果要实际应用还需要完善,比如在返回的时候终端执行的runnable可参考我的另外一篇文章如何终端执行的java线程)
也许网上有很多关于QQ游戏大厅的分析或者类似上面的例子,但是我想做进一步的分析。
1.我们知道一个activity具有严格意义上的生命周期必须要在ActivityThread里面去创建,所以通过DexClassLoader加载的ActivityB是没有生命周期的,它也就是一个普通的类;
2.有人会问,为什么还要让ActivityA 来加载ActivityB,而不是直接ActivityA去load 另外一个类比如classC呢? 这个问题很简单,因为我们在打包成APK的时候,有activity会更方便和直观(自己去体会)。简单的游戏,往往一个activity就够了。那么ActivityA 也仅仅只需要加载一个类实例。
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有新闻资料载入中……
新品测试表

参考资料

 

随机推荐