Android login Blocker implementation method (i)

Source: Internet
Author: User
<span id="Label3"></p><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;">For the app side, it will be a great user experience to ensure that users can automatically continue their Pre-logon operations after logging in. So it took a bit of time to think of two ways to achieve that kind of demand.<br style="text-align:left;text-indent:2em;"></p></p><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;">This article is about the first way, the way to realize this approach is basically this:</p></p><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;"><strong> <span style="text-decoration:underline;">When performing an operation that requires a login state, the action is referred to the interceptor, which delays the operation until the login is Successful. </span></strong><br style="text-align:left;text-indent:2em;"></p></p><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;">For example, users want to view personal data, the usual practice is to determine the login or not, if not logged in, you have to log in first, and then return from the login page after the corresponding jump in Onactivityresult. But if you use interceptors, you simply pass on the necessary information from your profile page (such as tagging the activity Action) to the interceptor, the Interceptor is processed, and then jumps to the profile page, so you only need to be concerned about your original needs and view your Profile.</p></p><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;">Next look at the Code:<br style="text-align:left;text-indent:2em;"></p></p><pre>Public void jumptoactivity (context ctx, string target, bundle params)   {jumptoactivity (ctx, target, params, new intent (ctx, getloginclass ()));} /** *  *  @param  ctx *  @param  target *              target Activity's action *  @param  params *              parameters that need to be passed to the target activity  *  @param   loginintent *             intent with parameters pointing to the login page  */public void jumptoactivity (context ctx, string target, bundle  Params,intent loginintent)  {if  (textutils.isempty (target)  | |  loginintent == null) throw new runtimeexception ("no target activity."); Jumpinvoker invoker = new jumpinvoker (target, params);if  (logon ())  {invoker.invoke (ctx);  else {loginintent.putextra (invoker, invoker); loginintent.addflags (Intent.FLAG_ACTIVITY_NEW_ TASK); ctx.startactivity (loginintent);}}</pre><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;">The code Jumpinvoker object is the logical performer after successful login, it will be transferred to the login module, after successful login, execute the Invoke method to jump to the specified page, see code:</p></p><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;"></p></p><pre><pre>@Overridepublic void Invoke (Context ctx) {Intent it = new Intent (mtargetaction); it.putextras (mdata); it.addflags ( intent.flag_activity_new_task); ctx.startactivity (it);}</pre></pre><p><p><br style="text-align:left;text-indent:2em;"></p></p><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;">How to Use:</p></p><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;">1. Make a profit Invoker object in the place where the login succeeds, call the Invoker.invoke method.</p></p><pre><pre>Invoker Invoker = getintent (). getparcelableextra (interceptor.invoker); invoker.invoke (getapplicationcontext ());</pre></pre><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;">2. To jump to the activity shown after login, you can use the Jumptoactivity method in the code to <span style="background-color:rgb(248,248,248);">pass in the action and parameters (not Required) of the target Page. </span><br style="text-align:left;text-indent:2em;"></p></p><p><p><br style="text-align:left;text-indent:2em;"></p></p><p style="text-align:left;text-indent:2em;"><p style="text-align:left;text-indent:2em;">The source code and jar package see the attachment, which only implements the logic of the login Jump. For other needs, such as collection click, after login automatically collection, you can also refer to the implementation of interceptor and Invoker Interface.</p></p><p><p>This article is from the "Android Pool" blog, so be sure to keep this source http://yeerik.blog.51cto.com/10547727/1681729</p></p><p><p>Android login Blocker implementation method (i)</p></p></span>
Related Article

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.