"Android-tips" How to get Activity objects in view

Source: Internet
Author: User

(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?
    1. 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?
    1. Public Gameview (Context context) {
    2. super (context);
    3. Activity activity;
    4. Activity= (Activity) context;
    5. }

"Android-tips" How to get Activity objects in view

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.