android - What context should I use when sending an Intent to an activity in a separate DEX file? -
i have android activity located in separate dex file want launch android app. exception after starting intent.
didn't find class "com.example.testproject.sampleactivity" on path: /data/app/com.example.testproject.apk
i built activity class , let eclipse put in dex file
public class sampleactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //setcontentview(r.layout.activity_sample); setcontentview(getintent().getintextra("layout", -1)); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.sample, menu); return true; } }
i added activity main apps manifest file
<activity android:name="com.example.testproject.sampleactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity>
i added activity_sample.xml layout file main apps project pass via intent other activity
then main app build intent call other activity follows
string p = environment.getexternalstoragedirectory().getpath() + "/classes.dex"; classloader dexloader = new dexclassloader(p, getcachedir().getabsolutepath(), null, getclassloader()); try { class<?> activityclass = dexloader.loadclass("com.example.testproject.sampleactivity"); intent intent = new intent(intent.action_main); intent.setclass(getapplicationcontext(), activityclass); intent.putextra("layout", r.layout.activity_sample); startactivity(intent); finish(); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); }
the class loaded okay after calling startactivity() exception noted above. seems problem context of intent since exception shows class being looked in /data/app/com.example.testproject.apk not in apk (the dex file on sd card).
any ideas how resolve issue?
this won't work. activities specified in androidmanifest.xml of apk must defined in main classes.dex of apk.
Comments
Post a Comment