Nested inner Activity class in android

后端 未结 3 2000
悲&欢浪女
悲&欢浪女 2021-01-18 01:16

Is declaring a class that extends Activity inside another Activity class possible? If it is, how would I register that class in the manifest? Also, is that something that ca

相关标签:
3条回答
  • 2021-01-18 01:36

    No, that's not possible. After all, the Android operating system will need to instantiate the Activity if it is started at any point (say, if you start it through an intent), and it's impossible to instantiate an ItemClass without a parent ListClass.

    Remember that each Activity is completely independent and can be started at any point through an intent.

    0 讨论(0)
  • 2021-01-18 01:45

    Yes, it does work -- it is just another class -- you just need to declare your activity using inner class notation in AndroidManifest.xml:

    <activity android:name=".ListClass$ItemClass"/>

    Seems to work fine for me, but perhaps when this question was asked, it wasn't supported in older versions of Android?

    Not sure WHY you'd want to do this, but you can.

    0 讨论(0)
  • 2021-01-18 01:53

    I'd also be curious why you'd want to do this.

    However, I don't see any reason why it wouldn't work. Couldn't you reference it in the AndroidManifest as you normally would as long as both classes are public? i.e. com.falmarri.ListClass.ItemClass?

    Edit: Nevermind, this doesn't work as EboMike pointed out.

    0 讨论(0)
提交回复
热议问题