在Android中我有一些活动,比方说A,B,C.
在A中,我使用此代码打开B:
Intent intent = new Intent(this, B.class);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
在B中,我使用此代码打开C:
Intent intent = new Intent(this, C.class);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
当用户点击C中的按钮时,我想返回A并清除后栈(关闭B和C).因此,当用户使用后退按钮B和C将不会显示时,我一直在尝试以下内容:
Intent intent = new Intent(this, A.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但是当我回到活动A时,如果我使用后退按钮,B和C仍然会出现.我怎么能避免这种情况?
在Objective C中,我一直使用以下代码来散列字符串:
-(NSString *) sha1:(NSString*)stringToHash {
const char *cStr = [stringToHash UTF8String];
unsigned char result[20];
CC_SHA1( cStr, strlen(cStr), result );
return [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15],
result[16], result[17], result[18], result[19]
];
}
Run Code Online (Sandbox Code Playgroud)
现在我需要相同的Android,但无法找到如何做到这一点.我一直在寻找这样的例子:在Android上进行SHA1加密? 但这并没有给我与iPhone相同的结果.谁能指出我正确的方向?
可能重复:
如何在android中将阴影设置为View?
在我的Android应用程序中,我需要一个带圆角的布局,背景应该有一些透明度.为此,我使用这个xml,它工作正常:
customshape.xml:
<shape android:shape="rectangle">
<gradient android:startColor="#E2FFFFFF" android:endColor="#E2D0E3E5" android:angle="270"/>
<corners android:radius="10dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
style.xml:
<style name="LinearLayoutRoundCorners">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@drawable/customshape</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我还需要在布局的右侧和底部有一个小阴影.我找不到办法做到这一点.我已经看到了一个黑客,你把另一个布局放在后面,使它看起来像一个阴影,但这对我不起作用,因为我的布局有透明度,所以看起来不会很好.如何在不使用图像作为布局背景的情况下在布局上获得漂亮的阴影效果?
在Android应用程序计费中,是否可以使用一个查询以某种方式查询所有产品的(价格)信息?最理想的情况是,您可以传递产品ID,并返回信息.
我正在寻找的是Android Market的SKProductsRequest等价物.http://developer.apple.com/library/ios/#documentation/StoreKit/Reference/SKProductsRequest/Reference/Reference.html#//apple_ref/occ/cl/SKProductsRequest
在Android中,我使用单行edittext,重力设置为居中.在模拟器中,这个功能很好,提示和闪烁的光标都显示出来.在设备上测试(Xperia X10)时,提示文本和闪烁光标都不会显示.闪烁的光标仅显示我是否在edittext中输入了一些文本.
这是我的编辑文本,任何人都可以看到是否缺少某些东西?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ellipsize="end"
android:maxLines="1"
android:gravity="center"
android:layout_gravity="center"
android:hint="Some hint text"
></EditText>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我想要的是:
我用上面的代码得到了什么(没有游标的空edittext):
我有一个MySql服务器的问题导致它一直冻结.在phpMyAdmin中,当发生这种情况时,我可以在"显示进程列表"中看到用户"未经验证的用户"的许多进程,其中命令为"connect",状态为"从网络读取".
数据库正在使用InnoDB,但我也使用一个运行MyISAM的表来执行全文搜索.服务器有大约4GB的内存,使用不到500MB.
我一直在使用来自MySql的慢查询日志来查找不使用索引的查询.我还认为我需要对服务器变量进行一些更改/调整.
我真的可以在这里使用一些帮助,因此我在这里发布SHOW GLOBAL STATUS和SHOW GLOBAL VARIABLES,也许你可以给我一些如何设置变量的想法?
当前显示全球状况:
Variable_name Value
Aborted_clients 730
Aborted_connects 35
Binlog_cache_disk_use 0
Binlog_cache_use 0
Binlog_stmt_cache_disk_use 0
Binlog_stmt_cache_use 0
Bytes_received 31558148370
Bytes_sent 556410688609
Com_admin_commands 4565
Com_assign_to_keycache 0
Com_alter_db 0
Com_alter_db_upgrade 0
Com_alter_event 0
Com_alter_function 0
Com_alter_procedure 0
Com_alter_server 0
Com_alter_table 3
Com_alter_tablespace 0
Com_analyze 0
Com_begin 168
Com_binlog 0
Com_call_procedure 0
Com_change_db 26791502
Com_change_master 0
Com_check 0
Com_checksum 0
Com_commit 0
Com_create_db 0
Com_create_event 0
Com_create_function 0
Com_create_index 0
Com_create_procedure 0
Com_create_server 0
Com_create_table 0
Com_create_trigger …
Run Code Online (Sandbox Code Playgroud) 在Android中,我使用以下方法来查看sqlite数据库是否存在以及是否可以打开它并使用它.
如果它未通过此测试,我将从资产中复制数据库文件(这应该只发生一次,当用户首次启动应用程序时).
/*
* Check if the database already exist to avoid re-copying the file each time you open the application.
* @return true if it exists, false if it doesn't
*/
private boolean checkDataBase() {
SQLiteDatabase checkDB = null;
try {
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
} catch(SQLiteException e) {
//database does't exist yet.
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
Run Code Online (Sandbox Code Playgroud)
问题是我收到用户的报告说他们的数据已被清除,在调查时我可以看到数据库被资产中的数据库替换.因此,出于某种原因,即使用户已经有数据库文件,有时SQLiteDatabase.openDatabase()也会引发错误.我自己无法重现这个问题,但似乎有些用户会发生这种情况.
任何人都知道问题可能在这里?有没有更好的方法来进行此测试?
我的Android应用需要用户创建一个帐户才能使用该应用.帐户信息存储在SQLite数据库中.当应用程序启动时,我会检查用户是否有帐户,如果没有,我会为用户显示注册活动.
现在,我收到用户的报告,即使他们已经创建了帐户,他们有时也会参与注册活动.当他们关闭应用程序并再次重新打开它时会发生这种情况.
这是我正在使用的代码,我需要弄清楚问题可能是什么:
//MyApplication.java
public class MyApplication extends Application {
private DataBaseUtility dbu;
public boolean hasAccount;
@Override
public void onCreate() {
super.onCreate();
//Init sqlite database
this.dbu = new DataBaseUtility(this);
//This loads the account data from the database and returns true if the user has already created an account
this.hasAccount = loadAccount();
}
public boolean loadAccount() {
boolean loadedData = false;
String query = "SELECT data FROM tblaccount WHERE tblaccount.deleted=0";
Cursor cursor = this.dbu.getCursor(query);
if (cursor != null) {
while (cursor.moveToNext()) …
Run Code Online (Sandbox Code Playgroud) 我在Asp.net的登录页面上有一个奇怪的问题,这个问题只发生在Safari上.
验证用户后,我从数据库中获取用户的名称(数据库中的字段为UTF8)并将其保存在cookie中.问题是,当用户的名字带有特殊字符时,我会被重定向到我来自的页面而不登录.例如"Moller"工作正常,用户登录但不是"Møller".
同样,这只发生在Safari上,当我在名字中有特殊字符时.无效的行是:Response.Cookies ["userInfo"] ["name"] = getNameFromUserid(userid);
这是我的代码:
string userid = validUserWithEmail(TextBoxEmail.Text, TextBoxPassword.Text);
if (userid != null) {
//VALID USER
Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(30);
Response.Cookies["userInfo"]["name"] = getNameFromUserid(userid);
FormsAuthentication.RedirectFromLoginPage(userid, CheckBoxPersistCookie.Checked);
}
else
{
//NOT A VALID USER SHOW A MESSAGE FOR THE USER OR SOMETHING
}
Run Code Online (Sandbox Code Playgroud) 我在Android中使用Sqlite并从数据库中获取值,我使用这样的东西:
Cursor cursor = sqliteDatabase.rawQuery("select title,category from table", null);
int columnIndexTitle = cursor.getColumnIndex("title");
iny columnIndexCategory = cursor.getColumnIndex("category");
cursor.moveToFirst();
while (cursor.moveToNext()) {
String title = cursor.getString(columnIndexTitle);
String category = cursor.getString(columnIndexCategory);
}
cursor.close();
Run Code Online (Sandbox Code Playgroud)
我想创建自己的光标,这样我可以做的getColumnIndex()
,并getString()
用一个方法.像这样的东西:
String title = cursor.getString("title");
Run Code Online (Sandbox Code Playgroud)
我想创建自己的类来扩展我得到的光标sqliteDatabase.rawQuery
,但我不知道如何实现这一点.我应该扩展SQLiteCursor还是应该如何做?它甚至可能是一个好主意吗?