开发者

Sending context/activity? Leaks? - Android

开发者 https://www.devze.com 2023-02-09 23:11 出处:网络
I\'m having an application with different views, and when I\'m \"flinging\" at right or left another view pops in and the other slides out. Most of the application is based in that activity.

I'm having an application with different views, and when I'm "flinging" at right or left another view pops in and the other slides out. Most of the application is based in that activity.

Since every view has buttons and lists (which you are supposed to interact with), the activity class is getting rather big and I was thinking of separating it. But which is the best way to do that?

Should I create classes that gets the activity context so I can declare the buttons value (findviewbyid()) etc. or is there another way to do this.

Is there a danger in sending the activity context? Is getApplicationContext() better to use for a time like this?, or should I just开发者_开发技巧 keep working on the class which is getting quite big?

Maybe there is a better way to do this?


I think the best way to do this would be to create a class that extends the View, and put all your child views in there. You'll still have to pass your context, but this way it'll be managed properly by the parent class.

I had a similar dilemma:

Safe to pass instance of an Activity to another object?

0

精彩评论

暂无评论...
验证码 换一张
取 消