Android ActivityGroup - NullPointerException -
i'm trying use activity groups - since use tabs, , want have tabs when loading , activity after list item clicked,. i'm getting nullpointerexception in following line:
view view1 = s1_group.group.getlocalactivitymanager() .startactivity("s1", intent) .getdecorview();
code .. .
lv.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent intent = new intent(getapplicationcontext(), s1.class); intent.addflags(intent.flag_activity_clear_top); log.d("test","before view"); try{ view view1 = s1_group.group.getlocalactivitymanager() .startactivity("s1", intent) .getdecorview(); settings_group.group.setcontentview(view1); } catch (exception e){ log.e("test","view failded:"+e); } ....
update: how group activity is: couldn't find issue.,
public class s1_group extends activitygroup { public static s1_group group; private arraylist<view> history; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); this.history = new arraylist<view>(); group = this; view view = getlocalactivitymanager().startactivity("f1", new intent(this, f1.class).addflags(intent.flag_activity_clear_top)).getdecorview(); setcontentview(view); } }
i had same problem. solve decomposed multi-call line 3 lines first answer suggested:
localactivitymanager processmanager =activitygroup.group.getlocalactivitymanager(); window w = processmanager.startactivity("activityone", myintent); view view = w.getdecorview();
then discovered first line problem one. because calling activityone activity outside of activity group (it activity under different tab), static "activitygroup.group...." has not yet been initialised. rather kludgy fix switch tab , tab before launching intent. add following before code above:
appname.switchtotab(2); appname.switchtotab(1);
that did trick , can't see tab switch. more tidy solution maybe switch tabs on startup ensure initialised...
Comments
Post a Comment