Summary of reasons why ActivityIntent explicit jump fails in Android

Scene reconstruction

There are two pages in the app, namely A and B. By using Intent, page A jumps to page B, but in the end the jump is not realized. After the break point, it is found that the corresponding code is run.

Possible Causes

1. The task stack is recycled by the system

The title of this question may be wrong, but the general meaning is that the task stack where the target needs to be jumped has been recycled by the system. We can achieve the jump by setting setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .
principle:

To set this state, it will first check whether there is a task stack with the same affinity as the started Activity (i.e. taskAffinity, please note that the affinity of activities in the same application is the same). If so, this stack will be directly Move the whole to the foreground and keep the status in the stack unchanged, that is, the order of activities in the stack remains unchanged. If not, create a new stack to store the activated activities. Quoted from the article
: https://blog.csdn.net/ u010389391/article/details/78558475

2. Startup mode conflict

This problem is caused precisely by setting Intent.FLAG_ACTIVITY_NEW_TASK in the previous point.
Principle:
Intent.FLAG_ACTIVITY_NEW_TASK will set the startup mode of the target activity to be jumped to singleTask . If the startup mode of the target activity is singleTop, there will be a conflict in the startup mode.

3. Parcelable serialization error

If you pass an object in the intent object, there may be a conflict in the serialization of the object, and the intent cancels the jump. The specific situation is: there are internal classes in the data bean, and only ben is Parcelable serialized, but its internal internal classes are not Parcelable serialized.
We need to check whether there is any problem with the serialization of the corresponding data bean.
In addition: If there is an error in serialization, there may not be a jump failure problem, but the correct data will not be obtained after the jump.

Conclusion

There should be many other situations where the page jump fails. I just listed the three situations that I know of. In addition, the principles of these three situations that I described may not be correct, so if there are any mistakes, I hope you can tell me. Thank you for being corrected so as not to mislead others! I also hope to know more about the types and reasons of other intent jump failures. If anyone knows about it, I hope you can give me some advice. If I learn about other types in the future, I will continue to update them. Thank you again! !

Guess you like

Origin blog.csdn.net/qq_39734865/article/details/102266737