I'm a self-taught passionate FullStack developer from China
About me
-
💼 Fullstack Engineer
-
❤️ I love writing code, communication with friends
-
💬 Ask me about anything
目标方法前置检验模型设计与实现
以登录+优惠 跳转到目标界面为例:
当我跳转到登录之后,此时不点击登录按钮;按正常情况 Queue中还存在优惠的Valid没有弹出,此时在登录界面用户不再执行登录操作,直接回退到上一个界面,由于全局单例中保存了优惠Valid,而优惠Vlid可以传入类似Context等变量,极易导致内存泄露
比如说我做登录跳转,我先调方法,但是我登录失败了,我 回过头,我直接去登录界面去跳转,那我跳转成功,肯定统一调docall 对不对,那这时候,我因为是直接去登录页跳转的,按道理和某些界面调docall,跳转的登录界面不一样是吧,这种情况的话,不应该触发call吧?
如题
如题,有几个地方需要登录验证。
1.public void onClick(View v){
SingleCall singleCall = SingleCall.getInstance();
singleCall.addAction(HomeFragment.this).addValid(new LoginValid(getActivity()) );
switch(){
case 1:
whichCall = 1;
singleCall.doCall();
case 2:
whichCall = 2;
singleCall.doCall();
}}
2.在onCreate()中初始化,并且在PopupWindow中也做了singleCall 的非空判断
第一种方法是没问题的,第二种报错
java.lang.NullPointerException: Attempt to invoke interface method 'void com.toptechs.libaction.action.Valid.doValid()' on a null object reference at com.toptechs.libaction.action.SingleCall.doCall(SingleCall.java:45)
请问能给个解决思路吗?
Valid中check过程是一个异步的操作才能知道结果,请问如何实现呢
public class CallUnit2 {
//目标行为
private Action action;
//目标条件
private Queue validQueue = new ArrayDeque<>();
//上一个执行的valid
private Valid lastValid;
private static CallUnit2 instance;
private CallUnit2() {
}
public static CallUnit2 getInstance() {
if (instance == null) {
instance = new CallUnit2();
}
return instance;
}
public CallUnit2 setNewAction(Action action) {
clear();
this.action = action;
return instance;
}
public CallUnit2 addValid(Valid valid) {
if(!valid.check()){
validQueue.add(valid);
}
return instance;
}
public void doCall() {
if(action == null){
return;
}
if(lastValid != null && !lastValid.check()){
//action.error(lastValid);
clear();
return;
}
if (validQueue.size() > 0) {
lastValid = validQueue.remove();
lastValid.doValid();
} else {
action.call();
clear();
}
}
private void clear(){
validQueue.clear();
lastValid = null;
action = null;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.