Android transmits data in a normal class (non-activity, mostly adapter) to a NULL solution: Transfer data in startactivity with intent

Source: Internet
Author: User

This is the bundle is not transmitting data, get to

This occurs because there is no context in the non-activity class, and the context is required to transfer data in the activity.

I have collected two solutions.

1.

Declare an activity (or context) in the activity that invokes the adapter.

Public static Activity mactivity;

And then assign a value to mactivity in the OnCreate function.

mactivity = this;

You can then invoke this static mactivity in adapter to start the activity.

Activity.mActivity.startActivity (intent);

The activity that starts this way is the data that can be obtained.

2.

Get a context startup activity directly.

GetContext (). StartActivity (intent);

This is also possible to obtain data, I think this method may be problematic, but the level is limited, do not know what the problem.

So that we can happily transfer data in non-activity.

By csdn turn a few stickers, reading volume is my original post several times, add a anti-theft link:zhangjiuding

Android transmits data in a normal class (non-activity, mostly adapter) to a NULL solution: Transfer data in startactivity with intent

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.