Data transfer between two activity in Android

Source: Internet
Author: User

First of all, this article is my original csdn above the blog, for various reasons, do not want to use CSDN blog, so the article moved to the present Cnblog.

Hello everyone, today I finally opened their own blog, very happy to share my learning experience with everyone, I hope we can progress together oh, nonsense not to say, look at me today to learn some of the problems and solutions Android

First the version of Eclipse I used was posted: adt-bundle-windows-x86-20130917 This is an integrated version that does not require configuration of the SDK and ADT, but requires manual configuration of the JDK!

In fact, different versions of Eclipse in the development of Android programs will be slightly different, let me start with the development of my Android program, I learned today is to pass data between two activity, below is my first activity, Is the interface used to calculate the multiplication of two numbers.

And here's my second activity.

The main purpose of the program is to display the results of the first activity in a second activity

but at the beginning my Android program code was

This is the main code in the first activity

The code for the second activity is

Edit without any errors, but run the program, the following interface appears


When you click the Calculate button, the following conditions occur:

Check for Logcat hints in eclipse

The reason for the error is probably that an activity parameter is not passed to the second activity, causing the second activity to receive a null parameter, and then cause the program to run an error, after its own careful check out, the program to make the following modifications :

The first activity program is modified as follows:

Make the following changes to the program in the second activity:

Run the program again to get the first and second correct results at the beginning

Analyze the reason:

when you invoke another activity in the activity , you need to call startactivity (Intent i), and if you need to pass the data while calling another activity, But in my version of Eclipse, I didn't pass the data correctly.

Workaround:

The ability to encapsulate data using a Android.os.Bundle object, passing data or parameters to pass through bundles to pass data between different intent

Data transfer between two activity in Android

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.