android--Fragmentation Transaction call failed

Source: Internet
Author: User

Encounter a situation:

In a timer, the network request query order payment status is initiated once per second, if the payment is successful, a message is sent in response;

If the message is received in handler, control the fragmentation switch.

The result encountered an error: The Fragment switch transaction error, there is a null object call BeginTransaction ().

Cause: Because the timer makes a request every second, the response of the network request from the last second is not returned, the next second is issued; results after the response of the last request arrives, the fragmentation switch is controlled, and the Fragment object is replaced (but not destroyed), and the response of the second network request is returned after the page switchover.  So the fragments that were replaced still emit information based on the response result, and the handler response information controls the fragmentation switch, at which point the fragment is not in any activity and therefore cannot get the Shard Manager through Getfragmentmanager (), so at this point Getfragmentmanager (). BeginTransaction () will have an error.

Workaround: Control how often network requests are made

In the timer, add a judgment condition, every 5 seconds (self-determined, long enough), send a network request.

android--Fragmentation Transaction call failed

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.