Android gets the return value of the previous activity to set the tolerance of the current button
Every time I want to repost others' articles, I don't have to write it myself. I really want to save time, but the journey is so hard. Every time I read others' blogs and do it myself, I will encounter various problems, people's blogs take just a few steps. However, when I follow these steps, I will encounter strange problems, now I think of the lyrics of Qu wanting's song "There is nothing different". Despite the pain and bitterness, it is always a good trip, as long as I cannot afford to lose my dream, never stop. I 'd like to summarize it myself !!
First, I added a new button for the app that previously created all projects, requiring that the button cannot be pressed before the value returned by the previous activity is obtained, so that I can find the method, the startActivityForResult method is used to obtain the return value of the previous page, assign this value to the variable, and set switch on the page to judge the value of this variable, in this way, the button can be set according to nature, and other content can be set.
I will not write any explanation about startActivityForResult. For more information, refer to other people's instructions. I feel that the description is good. This is the link address.Http://www.cnblogs.com/lijunamneg/archive/2013/02/05/2892616.html
Problems encountered during implementation:
(1) the current page cannot obtain the return value of the previous page. The resulting data always reports an error, saying that it is null. The callback method is called every time startActivityForResult is disabled. The intent is null, then I entered the jump page, which gave me a headache. So I added logs to various places to view the output, but I had no choice but to find a solution on the Internet. Finally, I found the solution:
For example, Activity1 has the onActivityResult method, and Activity2 has the setResult method. After Activity2 is disabled, the onActivityResult method of Activity1 should be triggered. However, android: launchMode = "singleTask" of activity2 in my manifest file ", change Activity to singleton mode, and the onActivityResult of Activity1 cannot be triggered. Change android: launchMode = "singleTask" to android: launchMode = "singleTop.
Then we can finally do it !! Difficult.
(2) It is also difficult to set the clickability of the button. Find the control first, and then setClickable (false). It is useless .... Later, the method for searching the Internet was found to be written in front of setOnClickListener, which made the previous settings invalid because there was a piece of code in setOnClickListener.
if (!isClickable()) { setClickable(true); }
Then change it to the end.