문제

I have a class defined as

public class viewGroups extends ListActivity

Somewhere in the class I have

objItem = new clsContactGroups(context);

I am wondering what is advised to be used here? Which context? I know four choices, but maybe there are others...

this
this.getApplicationContext()
this.getBaseContext()
this.getParent()

I use this Context to show a Toast. So I would like to show on the front-most view visible.

도움이 되었습니까?

해결책

Use this. The toast will be associated with your ListActiviy, which is what you are looking for. The ApplicationContext is not suitable (I'm not sure what would happen) and I think the getBaseContext() is probably going to return the same as the Application Context. getParent() would be a good choice if your activity is embedded in another, but this should be rare.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top