Simple example of Android login processing (source code download)

Simple example of Android login processing

Today, I'd like to sort out what I wrote in the project about some interfaces that need to be logged in and judged. A simple demo is arranged here to simulate the interface jump processing under login and non login conditions,

The effect is shown in the figure:

The above simulates the interface jump and current interface event processing under the condition of no login and logged in respectively. Next, let's look at the implementation.

Start with the core code:

It can be seen here that the most important thing is the first private modified startactivity method. Those who have seen the source code of the startactivity method of Android activity should know that it is actually the called startactivityforresult (intent, - 1). So let's also use its writing here. If it is equal to - 1, it means that there is a jump target activity. Then we get the class name of the target activity through intent. Getcomponent(). Getclassname(), and add it to the intent parameter again for the subsequent jump target after we log in successfully. Of course, other parameters in intent will always be carried. There is no need to worry about other parameters here. If it is not equal to - 1, the setresult callback is required. Therefore, we distinguish whether to continue to jump or call back the current interface by whether the requestcode is equal to - 1. The following two methods in the tool class distinguish the functions. Here we basically look at the system source code.

Then, perform secondary encapsulation. Here, you need to judge the current login status. Here, I also simulate the login status. The code is as follows:

In this case, if the login jump interface is basically required, you can directly call the starttologin method to jump according to the login status. As for the starttologinresult method, you still need to judge the login status when calling, distinguish processing, and then carry out callback processing in the onactivityforresult method. For the time being, I didn't expect other good methods. If you have any good processing methods, please give me more advice.

It's not over yet. Our login interface also needs some processing logic to cooperate. Let's see how to cooperate:

Finally, let's take a look at our calling method:

Basically, that's all. Some deficiencies in writing, please give more advice.

Demo address

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>