android gets the return value of the previous activity to set the pressability of the current button

Every time I want to repost someone else’s article, I don’t have to write it myself. I really want to save time, but the journey is so hard. Every time I read someone’s blog and do it myself, I will encounter various problems. So a few steps, but when I follow along, I will encounter strange problems, ah, now I think of the lyrics of a song by Qu Wanting, "Nothing Different", although I didn’t say it in pain, but how can I go all the way? It's all downwind. As long as you don't admit defeat for your dream, you will not stop no matter how hard you are. Or sum it up by yourself! !


First of all, I added a new button to the app of the previous project. The button is required to not be pressed before the value returned by the previous activity is obtained. In this way, I found a way to use the startActivityForResult method to get the previous page. Return the value, and then assign this value to the variable, set the switch in the page to determine the value of this variable, in order to set the pressability of the button, and also set other content.


I will not write about the explanation of startActivityForResult, refer to other people's, I feel that it is well written, this is the link address http://www.cnblogs.com/lijunamneg/archive/2013/02/05/2892616.html



Problems encountered in the implementation process:

(1) The current page cannot get the return value of the previous page, and the data obtained keeps reporting an error, saying it is null. Every time the callback method is called in startActivityForResult, the intent obtained is null, and then the jumped page is entered. This gave me a headache, so I added Log in various places to see the output, but couldn't find a solution online, and finally found a way:

For example: there is an onActivityResult method in Activity1, and a setResult method in Activity2. After Activity2 is closed, the onActivityResult method of Activity1 should be triggered, but the android:launchMode="singleTask" of activity2 in my manifest file makes the Activity into singleton mode. Then the onActivityResult of Activity1 cannot be triggered. Change android:launchMode="singleTask" to android:launchMode="singleTop". 


Then it's finally possible! ! It's difficult.

(2) I also encountered difficulties when setting the clickability of the button. I found the control first, then setClickable(false), and found it useless. . . . Later, I found a method on the Internet and found that it was written in front of setOnClickListener, which made the previous setting invalid, because there is a piece of code in setOnClickListener

    if (!isClickable()) {  
               setClickable(true);  
    }  

Then change it to the back.




Guess you like

Origin blog.csdn.net/u012457196/article/details/38418119