Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
it seems like managing views (Activities) from inside other Activities is bad
How do I know which Activity is changing the page with an Intent?
private void initDisplay() { btn = (Button) findViewById(R.id.button1); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { observable.setChanged(); // Custom event is assigned a page vo InteractionEvent evt = new InteractionEvent(this); PageChangeVO vo = new PageChangeVO(); // page vo's newPageName variable is set vo.newPageName = ActivityNames.SUB_PAGE; evt.pageVO = vo; observable.notifyObservers( evt ); observable.clearChanged(); } });}
@Overridepublic void update(Observable arg0, Object arg1) { Log.d(TAG, "UPDATE"); InteractionEvent evt = (InteractionEvent) arg1; evt.pageVO.activity = this.getApplication(); this.sendNotification(NotificationNames.CHANGE_PAGE, evt);}
@Overridepublic void execute(INotification notification) { super.execute(notification); Log.d(TAG, TAG+"::execute"); String mediatorName; InteractionEvent evt = (InteractionEvent) notification.getBody(); Activity act = (Activity) evt.pageVO.activity; Activity newAct; Mediator newMediator = null; Intent intent = null; // Remove the Mediator of the Activity doing the page change if (act.getClass().getName().equalsIgnoreCase(ActivityNames.APPLICATION) ) { mediatorName = MediatorNames.APPLICATION_ACTIVITY; if (getFacade().hasMediator(MediatorNames.APPLICATION_ACTIVITY)) { getFacade().removeMediator(MediatorNames.APPLICATION_ACTIVITY); } } if (act.getClass().getName().equalsIgnoreCase(ActivityNames.SUB_PAGE) ) { mediatorName = MediatorNames.SUB_PAGE_ACTIVITY; if (getFacade().hasMediator(MediatorNames.SUB_PAGE_ACTIVITY)) { getFacade().removeMediator(MediatorNames.SUB_PAGE_ACTIVITY); } } // Instantiate the new Activity if (evt.pageVO.newPageName == ActivityNames.APPLICATION) { newAct = new ApplicationActivity(); newMediator = new ApplicationMediator(MediatorNames.APPLICATION_ACTIVITY, (ApplicationActivity)newAct); intent = new Intent(act, ApplicationActivity.class); } if (evt.pageVO.newPageName == ActivityNames.SUB_PAGE) { newAct = new SubPageActivity(); newMediator = new SubPageMediator(MediatorNames.SUB_PAGE_ACTIVITY, (SubPageActivity)newAct); intent = new Intent(act, SubPageActivity.class); } getFacade().registerMediator(newMediator); act.startActivity(intent); act.finish();}
// Remove the Mediator of the Activity doing the page change