我对SQL很陌生,我真的只是与它进行交互以获得高分数据库的工作.我正在使用php脚本访问我的在线MySQL数据库.无论如何.
我所拥有的是2桌,球员和得分.播放器具有id,uniqueDeviceId和selectedname.分数具有您期望的常规事物.
我真的想在一个查询中做些什么(降低复杂性......)就是结合使用的语法
INSERT INTO scores VALUES
and INSERT INTO scores SELECT...
Run Code Online (Sandbox Code Playgroud)
变成某种怪物,就像
INSERT INTO scores(score,difficulty,playerid)
VALUES(TheScoreThatImProviding,TheDifficultyThatImProviding, (SELECT
id FROM player WHERE uniqueDeviceId = TheUniqueIdThatImProviding)
)
Run Code Online (Sandbox Code Playgroud)
如果这是有道理的.我想查找playerId(第三个"值"),并将该选择的结果与提供的VALUES的输入混合.
这可能吗?所有的谷歌搜索结果我发现要么全部有VALUES或所有SELECT.
所以,我认为我很聪明,并使用Android的安全唯一ID的各种哈希和排列来识别我的用户....
但事实证明,9774d56d682e549c是一个神奇的ID返回
Secure.getString(getContentResolver(), Secure.ANDROID_ID);
Run Code Online (Sandbox Code Playgroud)
对于大量的设备......似乎我构建的每个模拟器都具有相同的ID,并且许多其他人的手机(许多moto机器人!)和闪存的OS mods倾向于返回相同的重复值.非MotoDroid/Non-Flashed手机似乎都给了我一个独特的字符串.但是这个在我的DB中大约有60次!
我将优化我的应用程序以在注册之前检查该字符串,但是建议的方法是处理它以获得另一个唯一值?
我目前的想法是检查它,生成一个非常大的随机值,哈希它,然后存储比SharedPreferences然后使用ANDROID_ID或存储在sharedprefs中的那个(如果用户手机给出了值).任何人都有更好的想法,或者这似乎足以缓解这个疯狂的错误?
我有兴趣在将服务器上的JSON对象传输到请求该对象的移动设备之前压缩文本输出.对txt压缩的小测试将使其尺寸减小约80%!这非常适合移动设备!:)
我根本不需要保存我在服务器上创建的zip文件,只需将它驻留在内存中,然后将其回显.我可以在android端解压缩没问题.
无论如何,我做了一些操作,但我还没有能够提出任何有效的东西,这是我到目前为止所做的:
while($e=mysql_fetch_assoc($q))
$output[]=$e;
$zip = new ZipArchive();
$zip->addFromString("test",(json_encode($output)));
echo $zip;
Run Code Online (Sandbox Code Playgroud)
我知道我可能做了大量错误的事情,我对php不是很熟悉.我的$ q是一个包含大量sql行的游标,如果我使用print(json_encode($output));而不是所有的zip shenanigans,它可以正常输出原始文本.
我想它不一定是拉链压缩,但任何压缩都会有所帮助,如果你能指出我正确的方向,我可能会想出来.谢谢!
我在 Cloudformation 中定义了一个 EC2 资源,如下所示:
Resources:
FooInstance:
Type: 'AWS::EC2::Instance'
Properties:
blah: blah
blah: blah
UserData:
Fn::Base64: !Sub |
#!/bin/bash
/opt/aws/bin/cfn-init --stack ${AWS::StackId} --resource FooInstance --region ${AWS::Region}
Run Code Online (Sandbox Code Playgroud)
在 UserData cfn-init 块中是否有一个特殊的变量/替换字符串来引用“self”而不是显式声明FooInstance?这将有助于使我的团队的定义更易于复制。
谢谢!
所以,让我们说在我的主要活动中,我有一个像这样声明的数组,即使用任何main方法都没有任何问题:
public int currentPrices[] = {0,0,0,0,0,0,0,0,0};
Run Code Online (Sandbox Code Playgroud)
现在,我的buyDialog类如下:
package foosh.Frontier;
import android.app.Activity;
import android.os.Bundle;
import foosh.Frontier.*;
public class buyDialog extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// Be sure to call the super class.
super.onCreate(savedInstanceState);
currentPrices[0]=999;
//insert setup magic here
setContentView(R.layout.buydialog);
} }
Run Code Online (Sandbox Code Playgroud)
Eclipse坚持说当前的价格无法解决.如何将子活动链接到父活动的变量?
我可能做错了,因为我很擅长构建它们.但是这里是主线:
case R.id.buyButton1:
currentRes = masterRes.get(0);
Intent intent = new Intent();
intent.setClass(main.this, buyDialog.class);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud) eclipse android global-variables android-intent android-activity

什么在世界上可以给我这个额外的〜5-6像素的间距?这让我很生气,我尝试在父TableRow上设置填充/边距,每个按钮,文本视图,一切!
这是显示的XML布局:
<TableLayout android:id="@+id/tableLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" >
<TextView android:text="Resource1 - $Price" android:id="@+id/resourceText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="3"></TextView>
<Button android:text="@string/buybtn" android:id="@+id/buyButton1" android:onClick="buyButtonClick" android:layout_width="80dip" android:layout_height="36dip"></Button>
<TextView android:text="XXX" android:id="@+id/resourceHeld1" android:layout_width="30dip" android:layout_height="wrap_content" android:gravity="center"></TextView>
<Button android:text="@string/sellbtn" android:id="@+id/sellButton1" android:onClick="sellButtonClick" android:layout_width="80dip" android:layout_height="36dip"></Button>
</TableRow>
<View android:layout_height="1dip" android:background="#FF303030"/>
<TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Resource2 - $Price" android:id="@+id/resourceText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="3"></TextView>
<Button android:text="@string/buybtn" android:id="@+id/buyButton2" android:onClick="buyButtonClick" android:layout_width="80dip" android:layout_height="36dip"></Button>
<TextView android:text="XXX" android:id="@+id/resourceHeld2" android:layout_width="30dip" android:layout_height="wrap_content" android:gravity="center"></TextView>
<Button android:text="@string/sellbtn" android:id="@+id/sellButton2" android:onClick="sellButtonClick" android:layout_width="80dip" android:layout_height="36dip"></Button>
</TableRow>
etc etc etc copypasta
Run Code Online (Sandbox Code Playgroud)
我需要牺牲哪些鸡肉来填充那些填充物?在一个理想的世界中,我会轻轻推动1dip视图,在按钮底部有一个1dip的边距.
假设我正在使用意图将信息返回到调用当前活动的主类.
如果说,我有两种方法可能会重叠同一个字段会发生什么,例如:
myIntent.putExtra("returnVal1",1000);
// many lines of code, later on...
myIntent.putExtra("returnVal1",5);
Run Code Online (Sandbox Code Playgroud)
"returnVal1"会在意图中更新为5,它会保持在1000,还是会导致运行时崩溃?
提前谢谢,从手机发送,而不是在带有eclipse atm的计算机上,或者我会测试自己!
我实现了一个静态帮助程序类,可以帮助缓存和检索数据库中的一些只读,不可变,非易失性数据.
(剥离)示例:
public class CacheHelper
{
private static HashMap foos, bars;
public static Foo getFoo(int fooId) { /* etc etc */ }
public static Bar getBar(int barId) { /* etc etc */ }
public static void reloadAllCaches()
{
//This is where I need it to lock access to all the other static methods
}
}
Run Code Online (Sandbox Code Playgroud)
我为静态类读取它的方式,如果我将synchronized关键字添加到reloadAllCaches()方法,这将在该方法执行时对整个类应用锁.它是否正确?(编辑:是的,不正确.感谢您的回复.)
注意:我希望对getter方法的线程安全性和它们返回的对象保持不可知,因为这些数据永远不会发生变化,并希望尽快返回.
我知道生活在堆上的原始对象和对象,但是方法的数量如何影响对象的堆大小?
例如:
public class A {
int x;
public getX() { return x; }
}
public class B {
int x;
public getX() { return x; }
public getXString() { return String.valueOf(x); }
public doMoreInterestingStuff() { return x * 42; }
//etc
}
Run Code Online (Sandbox Code Playgroud)
实例化时,两个对象都在堆上,两者都有内存分配给它们的原语x,但由于有更多的方法签名,B分配了更多的堆空间?或者只是在permGen空间?在这个例子中它是微不足道的,但是当在任何给定时间内存在100,000多个这些对象时,我想它可能会加起来.
万岁的照片!这是将图片分配给背景时的样子,何时不是.


TableView如果图像大于桌子,我非常希望它不会伸展到顶部.我已经包含了一个空的"视图",以便为表的背景提供一些额外的空间,正如您可以在XML中看到的那样.试图用ScaleType搞乱,但这是一个洗.
如何让BG伸展以适应布局?我正在尝试优雅地处理"用户xxx的屏幕小于WVGA".显然,我缺乏恩典.
<TableLayout
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scaleType="fitXY"
android:background="@drawable/minetownx480"
>
<View
android:id="@+id/blankSpace"
android:layout_width="fill_parent"
android:layout_height="60dip" />
<TableRow android:id="@+id/widget40" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal">
<TextView android:id="@+id/moneyText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Money: $$$$$$$$$" />
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/savingsText" android:gravity="right" android:text="Savings: $$$$$$$" android:layout_weight="3" android:textSize="12sp"/>
</TableRow>
<TableRow android:id="@+id/widget41" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal">
<TextView android:id="@+id/wagonText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Wagon Space: XXX/XXX" />
<TextView android:id="@+id/loanText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Loans: $$$$$$$$" android:gravity="right" android:layout_weight="3" android:textSize="12sp"/>
</TableRow>
<TableRow android:id="@+id/widget42" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" >
<TextView android:id="@+id/daysText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Days Left: XX/XX" />
<TextView …Run Code Online (Sandbox Code Playgroud) 我正在做一个相当基本的游戏.在我的偏好中,可以选择更改难度设置.我希望能够以某种方式,在调用它的主要活动中,感觉他们是否已经改变了难度.(然后重启游戏)
由于异步处理偏好活动的方式,我遇到了困难.如果我在将意图发送到PreferenceActivity之前和之后添加逻辑来检查值(从菜单选择中),它确实不起作用......
有人能指出我如何序列化通常异步处理的一大块代码,或者知道如何改变偏好的想法?某个地方是否隐藏了一个监听器类?
为了后人的缘故,这里是处理意图的代码以及我如何失败.(片段,从内部菜单onOptionsItemSelected,在开关内)
case R.id.menuOptions:
String currentDifficulty = preferences.getString("difficulty","problem!");
Intent i = new Intent(this, prefs.class);
startActivity(i);
if (currentDifficulty.equals(preferences.getString("difficulty","problem!")))
return true;
else doNewGame();
return true;
Run Code Online (Sandbox Code Playgroud) android ×7
java ×2
php ×2
asynchronous ×1
background ×1
button ×1
classloader ×1
cloud-init ×1
cryptography ×1
eclipse ×1
heap ×1
json ×1
layout ×1
methods ×1
mysql ×1
padding ×1
put ×1
security ×1
static ×1
stretch ×1
tablelayout ×1
zip ×1