首先,我知道不应该在Android上杀死/重启应用程序.在我的用例中,我想在服务器向客户端发送特定信息的特定情况下出厂重置我的应用程序.
用户只能使用应用程序的一个实例登录服务器(即不允许多个设备).如果另一个实例获得"登录"锁定,那么该用户的所有其他实例都必须删除其数据(工厂重置),以保持一致性.
可以强制获取锁定,因为用户可能会删除应用程序并重新安装它,这将导致不同的实例ID,并且用户将无法再释放锁定.因此可以强行锁定.
由于这种力的可能性,我们需要始终检查具有锁定的具体实例.这是(几乎)对服务器的每个请求完成的.服务器可能会发送"error-lock-id".如果检测到,则客户端应用程序必须删除所有内容.
那是用例.不执行问题:
我有一个ActivityA启动Login ActivityL或应用程序的主ActivityB,具体取决于sharedPrefs字段.在启动L或B后,它自行关闭,只有L或B运行.因此,在用户已登录的情况下,B现在正在运行.
B开始C. C调用startService为IntentServiceD.导致这个堆栈:
(A)> B> C> D.
从D的onHandleIntent方法,事件被发送到ResultReceiver R.
R现在通过向用户提供一个对话框来处理该事件,在该对话框中他可以选择出厂重置应用程序(删除数据库,sharedPrefs等)
出厂重置后,我想重新启动应用程序(关闭所有活动),然后再次启动A,然后启动登录ActivityL并自行完成:
(A)> L.
Dialog的onClick方法如下所示:
@Override
public void onClick(DialogInterface dialog, int which) {
// Will call onCancelListener
MyApplication.factoryReset(); // (Deletes the database, clears sharedPrefs, etc.)
Intent i = new Intent(MyApp.getContext(), A.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MyApp.getContext().startActivity(i);
}
Run Code Online (Sandbox Code Playgroud)
这就是MyApp班级:
public class MyApp extends Application {
private static Context context;
@Override
public void onCreate() { …Run Code Online (Sandbox Code Playgroud) 是否可以从Symfony2/Doctrine中的现有数据库生成灯具?我怎么能这样做?
例:
我已经定义了15个实体,我的symfony2应用程序正在运行.现在有些人可以浏览到该应用程序,并且使用它已经插入了大约5000行,直到现在.现在我希望插入的东西作为固定装置,但我不想手工完成.如何从数据库生成它们?
我想根据百分比值计算颜色:
float percentage = x/total;
int color;
if (percentage >= 0.95) {
color = Color.GREEN;
} else if (percentage <= 0.5) {
color = Color.RED;
} else {
// color = getColor(Color.Green, Color.RED, percentage);
}
Run Code Online (Sandbox Code Playgroud)
我怎么能计算出最后的东西?如果黄色出现在50%就没问题.
我试过这个:
private int getColor(int c0, int c1, float p) {
int a = ave(Color.alpha(c0), Color.alpha(c1), p);
int r = ave(Color.red(c0), Color.red(c1), p);
int g = ave(Color.green(c0), Color.green(c1), p);
int b = ave(Color.blue(c0), Color.blue(c1), p);
return Color.argb(a, r, g, b);
}
private int ave(int src, …Run Code Online (Sandbox Code Playgroud) 两个条形图显示了游戏的进度.如果用户获得积分或时间等,则应更新progressBars:
private TextView tv;
private ProgressBar levelHoldBar;
private ProgressBar levelUpBar;
//...
private void updateViews() {
// ...
levelHoldBar.setMax(currentLevel.getThreshold());
levelHoldBar.setProgress(currentPoints > currentLevel.getThreshold() ? currentLevel.getThreshold() : currentPoints);
levelUpBar.setMax(nextLevel.getThreshold());
levelUpBar.setProgress(currentPoints > nextLevel.getThreshold() ? nextLevel.getThreshold() : currentPoints);
tv.setText(currentPoints+"/"+currentLevel.getThreshold());
Log.d(TAG, "hold prog/max "+levelHoldBar.getProgress()+"/"+levelHoldBar.getMax());
Log.d(TAG, "up prog/max "+levelUpBar.getProgress()+"/"+levelUpBar.getMax());
}
Run Code Online (Sandbox Code Playgroud)
即.输出:
12-03 17:48:33.918: DEBUG/MainActivity(6829): hold prog/max 20/20
12-03 17:48:33.918: DEBUG/MainActivity(6829): up prog/max 20/50
Run Code Online (Sandbox Code Playgroud)
到底Log.d(...)表示总是正确的价值观,但SOMETIMES的progressBars的可视化条不显示正确的进度变化.它们显示先前设定的进度,即使"最大"和"进度"的吸气剂返回正确的值(在示例中,条形图显示levelHoldBar约20%(而不是100%)和约2%(而不是40%) %)为levelUp-bar).我无法弄清楚,为什么日志输出是正确的但是drawables是错误的!?TextView(tv)正确更新!这里发生了什么?我该如何解决这个问题?
给定以下域模型,我想加载所有Answers,包括它们的Values 和它们各自的子子级,并将其放入 an 中AnswerDTO,然后转换为 JSON。我有一个可行的解决方案,但它遇到了 N+1 问题,我想通过使用临时@EntityGraph. 所有关联都已配置LAZY。
@Query("SELECT a FROM Answer a")
@EntityGraph(attributePaths = {"value"})
public List<Answer> findAll();
Run Code Online (Sandbox Code Playgroud)
@EntityGraph在该Repository方法上使用临时方法,我可以确保预取值以防止Answer->Value关联中出现 N+1 。虽然我的结果很好,但由于延迟加载s的selected关联,还有另一个 N+1 问题MCValue。
使用这个
@EntityGraph(attributePaths = {"value.selected"})
Run Code Online (Sandbox Code Playgroud)
失败,因为该selected字段当然只是某些Value实体的一部分:
Unable to locate Attribute with the the given name [selected] on this ManagedType [x.model.Value];
Run Code Online (Sandbox Code Playgroud)
我如何告诉 JPA 仅selected在值为 a 的情况下尝试获取关联MCValue?我需要类似的东西optionalAttributePaths。
我们如何启用对 spring 安全 kotlin DSL 的支持?
正如您从 IDE (IntelliJ) 的屏幕截图中看到的,DSL 不可用:
这是完整的SecurityConfig.kt文件:
package com.example.backend.core
import org.springframework.context.annotation.Bean
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
import org.springframework.security.config.web.server.ServerHttpSecurity
import org.springframework.security.web.server.SecurityWebFilterChain
@EnableWebFluxSecurity
class SecurityConfig {
@Bean
fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain? {
return http {
csrf { disable() }
formLogin { disable() }
httpBasic { disable() }
// ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我们的build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val springBootVersion = "2.4.2"
plugins {
id("org.springframework.boot") version "2.4.2"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.4.21"
kotlin("plugin.spring") version "1.4.21"
}
group = "com.example" …Run Code Online (Sandbox Code Playgroud) 我尝试使用Doctrine2为我的Symfony2应用程序构建一个manyToOne关系.我收到此错误,我不知道为什么:
app/console doctrine:schema:create
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
ATTENTION: This operation should not be executed in an production enviroment.
[Doctrine\DBAL\Schema\SchemaException]
There is no column with name 'activityGroup' on table 'activity'.
Run Code Online (Sandbox Code Playgroud)
这是两个类:http://pastebin.com/Ev7Rwgxr
我认为在Activity类上实际上有一个activityGroup ...那么这个错误试图说什么呢?
谢谢!
该线程是 Github 问题的延续: https://github.com/spring-projects/spring-data-r2dbc/issues/194
\n语境:
\n你好,
\n我刚刚尝试了一个非常简单的示例,基于两个反应性存储库:
\n给定 br一个 r2dbc crud 存储库,以及cr另一个 r2dbc crud 存储库:
br.findAll()\n .flatMap(br -> {\n return cr.findById(br.getPropertyOne())\n .doOnNext(c -> br.setProperty2(c))\n .thenReturn(br);\n })\n .collectList().block();\nRun Code Online (Sandbox Code Playgroud)\n此代码示例永远不会完成(只有前 250 个左右的条目到达.collectList操作员)。经过一番挖掘后,onBackpressureXXX在后面添加了一些运算符findAll可以通过......删除元素或缓冲它们来“修复”问题。
在这一点上,我的理解是,r2dbc 反应存储库不使用消费者反馈机制,这消除了 r2dbc 的大部分好处。
\n我错了吗 ?有没有更好的方法来实现同样的目标?
\n谢谢 !
\n@mp911de 的建议:
\n作为一般规则,避免在另一个流处于活动状态时创建流(名言:不要交叉流)。
\n如果您想获取相关数据,那么理想情况下将所有结果收集为列表,然后运行子查询。这样,初始响应流就会被消耗,并且连接可以自由地获取其他结果。
\n像下面的代码片段这样的东西应该可以完成这项工作:
\nbr.findAll().collectList()\n .flatMap(it -> {\n\n List<Mono<Reference>> refs = new ArrayList<>();\n for (Person p : …Run Code Online (Sandbox Code Playgroud) 给定一个包含大量项目的结果流,我想存储它们并处理潜在的并发冲突:
public void onTriggerEvent(/* params */) {
Stream<Result> results = customThreadPool.submit(/*...complex parallel computation on multiple servers...*/).get();
List<Result> conflicts = store(results);
resolveConflictsInNewTransaction(conflicts);
}
Run Code Online (Sandbox Code Playgroud)
我被困在如何store(...)有效地实施。在Result由描述数据,需要在其各自的数据库表被更新这两件不更改和拆卸对象。
@Value
public static class Result {
A a; // describes update for row in table a
B b; // describes update for row in table b
}
Run Code Online (Sandbox Code Playgroud)
A并且B每个引用两个用户,其中(u1, u2)是各自数据库表上的一个键。
@Value
public static class A {
long u1;
long u2;
// ... computed data fields ...
} …Run Code Online (Sandbox Code Playgroud) 首先,我想创建一个用户从我的Android应用程序向服务器发送一个后请求,该服务器使用Symfony2和FOSUserBundle.
最后,我想从移动应用程序登录用户,然后与服务器进行数据通信.
我知道如何在android-device上实现post-request.但我不知道如何配置FOSUserBundle和security.yml等以满足我的需求.虽然我可能需要一个_csrf_token或其他东西,我不知道从哪里得到它.
我已经将身份验证方法从form_login更改为http_basic,并认为这将是进行身份验证的最简单方法(使用https来保护密码).
但是现在......我需要做什么,以实现创建和登录没有表单的操作?我需要在移动设备上的后请求中添加什么内容?
感谢您的任何想法,意见和解决方案!
android ×4
java ×3
symfony ×3
doctrine-orm ×2
hibernate ×2
postgresql ×2
bundle ×1
colors ×1
entitygraph ×1
fixtures ×1
jpa ×1
kotlin ×1
progress-bar ×1
r2dbc ×1
spring ×1
spring-boot ×1
spring-data ×1