(Reproduced Please specify Source: Http://blog.csdn.net/buptgshengod)
today I want to realize the function of returning to the previous activity in view, think for half a day. Because while the view is contained in an activity, the object that is obtained directly in view with this is not activity but the view, which does not directly write the name of the activity. Then found this method and attached!
The first hypothesis is that view is defined in activity A to generate. Assuming that the class of view is called Gameview, then in a oncreat (), the activity object must be passed to Gameview's constructor.
[Java]View Plaincopyprint?
- gameview=New Gameview (this);
Gameview=new Gameview (this);
Because there is a constructor in view, as long as the context is passed to the newly defined activity, you can manipulate the activity in the view
[Java]View Plaincopyprint?
- Public Gameview (Context context) {
- super (context);
- Activity activity;
- Activity= (Activity) context;
- }
"Android-tips" How to get Activity objects in view