Dynamically create an activity

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 05:44:27

问题


I want to create an activity dynamically. Something like:

Activity a = new Activity();

Is it possible ? Do I need a special permission ? Or is it simply not possible ?

The error I get: I don't get any exception but the program stops when I try to use this instruction.


回答1:


You can't instantiate an Activity if it's not in the Manifest, so you can't create one dynamically.




回答2:


You can't create activity at run time so what you can u is create Layouts at the run time and change the layout according to the event...

here you are going to use layout change instead of starting a new activity




回答3:


Instead of multiple activities you can Fragments. You can use the same Layouts with Fragments and you can instantiate them dynamically and remove. In this way you can create a stack based application.




回答4:


are you trying to start an activity?

use context.startActivity(intent); where the intent defines what activity you want to start.



来源:https://stackoverflow.com/questions/6313610/dynamically-create-an-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!