我有一个活动A,它调用活动B.在活动B中,当我点击一个按钮时,调用finish(),然后调用活动B的onDestroy()并返回活动A.
根据android文档,在调用on onDestroy之前,将调用onSaveInstanceState(Bundle bundle),其中我执行以下操作.
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
System.out.println("Saving webview state");
Log.d(TAG, "In onsave");
wv.saveState(outState);
}
Run Code Online (Sandbox Code Playgroud)
并且下次从活动A开始活动B,
在oncreate()中,我执行以下操作:
onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if(savedInstanceState != null){
//restore webview
}else {
// code
}
}
Run Code Online (Sandbox Code Playgroud)
但是,在活动B中调用onDestroy之前,永远不会调用onSaveInstanceState方法.任何有关这方面的帮助将不胜感激.
编辑:如果这是不可能的.如果有办法存储webview状态,请告诉我
有没有办法在不使用@Value注释的情况下从spring中读取外部属性文件中的文本.例如:application.properties
var.foo="hello"
Run Code Online (Sandbox Code Playgroud)
我可以用弹簧豆注入它
@Value("${var.foo}") String value;
Run Code Online (Sandbox Code Playgroud)
作为类变量.有没有办法在不使用@Value注释的情况下包含此属性.类似于JSR bean验证的方式.
@NotNull(message={custom.notnull})
Run Code Online (Sandbox Code Playgroud)
并在ValidationMessages.properties文件中外部化此属性值.
例如,如果我有一个资源(Web组件)类,并且我必须使用Swagger注释来记录它们,
@controller
@path("/")
@Api(description = "User Resource API")
public class UserResource {
@Path("/users")
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "returns user details", notes = "some notes")
public User getUser() {
return new User(123, "Joe", "Montana");
}
}
Run Code Online (Sandbox Code Playgroud)
和模型,
@ApiModel("user model")
public class User {
@ApiModelProperty(value = "This represents user id")
private String id;
private String firstName;
private String lastName;
...
}
Run Code Online (Sandbox Code Playgroud)
如何将此字符串/句子/消息外部化为外部属性文件.我认为这适用于一般的Java注释和spring,而不是Swagger特有的.我指定Swagger的原因是,如果像hibernate验证一样,Java库可以选择在外部ValidationMessages.properties文件中指定这些消息,并且spring默认知道它可以获取(或者可以配置).
Swagger提供这样的选择吗?如果没有,我该如何设置?
根本问题是,我不想把我的代码/逻辑与文档相关的数据(元数据)混为一谈.
我如何使用java 8流获取此数据结构.
class A {
B b;
public A(B b) {
this.b = b;
}
}
class B {
List<A> as;
private int i;
public B(int i) {
this.i = i;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的对象结构.我想把它聚合到,
Map<A, List<B>> bs;
Run Code Online (Sandbox Code Playgroud)
从,
List<A> as = new ArrayList<>();
as.add(a1);
as.add(a2);
as.add(a3);
Run Code Online (Sandbox Code Playgroud) 如何重试可观察的源?
List<String> ids = new ArrayList<>(); // A,B,C
Observable.from(ids)
.retryWhen(errors -> {
return errors
.zipWith(Observable.range(0, 1), (n, i) -> i)
.flatMap(retryCount -> Observable.timer((long) Math.pow(2, retryCount), TimeUnit.MINUTES));
})
.subscribe(....);
Run Code Online (Sandbox Code Playgroud)
现在,如果我想传递其他值,而不是将// A,B,C作为id传递。我该怎么做?还是这是正确的方法?
我正在尝试使用jackson对象映射器将字节数组反序列化为java类型.
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class A {
String s;
String b;
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class B {
String c;
String b;
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class C {
List<CustomType> x;
}
Run Code Online (Sandbox Code Playgroud)
并使用杰克逊方法,
objectMapper.readValue(byte[] data, Class<T> type).
Run Code Online (Sandbox Code Playgroud)
因为我不确定字节数组包含什么对象,所以当它无法创建指定类型的对象时,我希望它失败.但是,objectMapper返回一个对象,其所有字段都初始化为null.我该如何避免这种行为?
Ex:
byte[] b; //contains Class B data
byte[] a; //contains Class A data
byte[] c// contains Class C data
A a = objectMapper.readValue(c, A.class) is returning
{s=null, b = null}
Run Code Online (Sandbox Code Playgroud)
这是我配置了ObjectMapper,
@Bean
public ObjectMapper …Run Code Online (Sandbox Code Playgroud) 我对js很新.如果这听起来很蠢,我很抱歉.但为什么下面的代码返回"undefined"
function NewPerson(name, age, sex){
this.name = name;
this.age = age;
this.sex = sex;
this.getName = function(){
//alert(this.name);
alert("The age is "+this.age);
};
}
var obj1 = new NewPerson("Mark",25,"Male");
alert("The age is as follows "+obj1.getName());
Run Code Online (Sandbox Code Playgroud)
//输出:
年龄为25岁.未定义年龄如下
我想调用一个每隔几秒返回一个值的方法.我尝试过使用Timerwith elapsedEventandler,但在这种情况下,方法的返回类型是无效的.我已经使用TimerTask该类在Java中执行相同的任务.
我希望它在.NET 2.0中,因为我正在使用Visual Studio 2005.
以下是我遇到麻烦的程序.我试图使用匿名方法,但response在这种情况下的值不存在于匿名方法之外:
public static string Run(string address)
{
string response = "A";
Timer t = new Timer();
t.Elapsed += delegate
{
response = callURL(address);
console.writeln(response);
// The actual response value is printed here
};
t.Interval = 3000;
t.Start();
Console.WriteLine("response string is " + response);
// response string is A
return response;
}
public static string callURL(string address)
{
className sig = new ClassName();
String responseBody = sig.getURL(address);
return …Run Code Online (Sandbox Code Playgroud) 这是我的 .properties 文件,
property.filename = logs/app.log
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = "%-5p %c{1} - %m%n
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = logs/app-%d{MM-dd-yy}-%i.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%-5level] %d{DATE} %-5p [%t] %c{1} - %msg%n
appender.rolling.append = true
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size = 10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 5
logger.rolling.name = org.springframework.boot
logger.rolling.level = info
logger.rolling.additivity = …Run Code Online (Sandbox Code Playgroud) java ×3
spring ×2
android ×1
annotations ×1
c# ×1
c#-2.0 ×1
jackson ×1
java-8 ×1
java-stream ×1
javascript ×1
json ×1
log4j2 ×1
properties ×1
rx-java ×1
spring-boot ×1