从外部DEX /罐装载活动 [英] Loading activities from external dex/jar

查看:189
本文介绍了从外部DEX /罐装载活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://android-developers.blogspot.in/2011/07/custom-class-loading-in-dalvik.html

该链接指向加载的类二敏捷,这是工作的罚款

This link refers loading of classes from Second Dex, this is working fine

, 我尝试添加一个活动二DEX,并试图从我MainActivity访问, 我是从我的MainActivity

Instead of calling a simple method available in Second Dex, I tried to add an activity in Second dex, and Tried to access from my MainActivity, I'm getting Classnotfound error when I try to access/start the activity using startActivity() from My MainActivity

我也尝试过使用PathClassLoader - 它也呈现出同样的错误

I also tried using PathClassLoader - its also showing same error

我们可以访问/加载活动present在二塞米松从MainActivity?

Can we access/load that Activity present in Second Dex from MainActivity?

什么是正确的方式,让多地塞米松文件的活动?

What it the proper way to keep activities in multiple Dex file?

在此先感谢

推荐答案

是的,你可以,你唯一需要的就是提活动的细节在应用程序的清单文件。

Yes You can, The only thing you need is to mention the Activity details in the application's manifest file.

另外,还要确保,该活动的布局文件是存在的。

Also make sure, the layout file for the activity is there.

例如:我打算从我的应用程序加载TestActivity库中的jar文件

Example : I'm planning to load TestActivity in a library jar file from My Application.

TestActivity.class(寓于JAR文件):

TestActivity.class (Resides in jar File):

public class TestActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getIntent().getIntExtra("LAYOUT", -1));
}

}

MainActivity.class(寓于应用程序项目)

MainActivity.class (Resides in Application project)

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);

    Intent intTest = new Intent(this, TestActivity.class);
    intTest.putExtra("LAYOUT", R.layout.activity_test);
    startActivity(intTest);
}

}

布局:actitivity.xml和activity_test.xml两者都应该驻留在应用程序的布局文件夹

layouts : actitivity.xml and activity_test.xml both should reside in application's layout folder.

需要提及的TestActivity在Manifestfile。

Need to mention TestActivity in Manifestfile.

<activity android:name="yourPackage.TestActivity"></activity>

这篇关于从外部DEX /罐装载活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆