我正在尝试将defaultValue设置为ListPreference项.
以下是我的preference.xml文件示例:
<ListPreference android:key="notification_delay"
android:title="@string/settings_push_delay"
android:entries="@array/settings_push_delay_human_value"
android:entryValues="@array/settings_push_delay_phone_value"
android:defaultValue="????">
</ListPreference>
Run Code Online (Sandbox Code Playgroud)
两个数组:
<string-array name="settings_push_delay_human_value">
<item>every 5 minutes</item>
<item>every 10 minutes</item>
<item>every 15 minutes</item>
</string-array>
<string-array
name="settings_push_delay_phone_value">
<item>300</item>
<item>600</item>
<item>900</item>
</string-array>
Run Code Online (Sandbox Code Playgroud)
当我进入首选项活动时,没有选择ListPreference的项目.我试图在"android:defaultValue"中设置一个类似于1的int值,选择"10分钟",但它不起作用.
<ListPreference android:key="notification_delay"
android:title="@string/settings_push_delay"
android:entries="@array/settings_push_delay_human_value"
android:entryValues="@array/settings_push_delay_phone_value"
android:defaultValue="1">
</ListPreference>
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我在使用此导航树在应用程序上实现导航时遇到问题:

后退按钮的标准实现很好.
尝试实现"向上"按钮时,问题就出现了.
我期待的是:
所以从不同的角度来说,我希望在后台堆栈上有这种行为:

Android文档(实现祖先导航)建议使用以下代码来处理导航:
Intent parentActivityIntent = new Intent(this, MyParentActivity.class);
parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(parentActivityIntent);
finish();
Run Code Online (Sandbox Code Playgroud)
但是因为详细活动的父活动在不同的导航路径上有所不同,所以我不知道它实际上是哪一个.所以我不能在Intent中调用它.
有没有办法知道Android后台堆栈中真正的父活动?
如果没有,有没有办法在这个应用程序中实现正确的导航?
在Android平台的支持库appCompat v7中,有一个android.support.v7.widget.LinearLayoutCompat类.
有人知道为什么这堂课存在吗?原始的LinearLayout类从API级别1开始存在,所以我不明白为什么有compat版本.
我想知道是否有一种方法可以在Eclipse下单击一下在多个设备/模拟器上安装和运行Android应用程序.
当我在多个(n)设备上测试布局时,我现在正在进行n次运行(实际上是ctrl-F11快捷方式),选择正确的设备,然后在每个设备上检查我的布局.
在连接到我的计算机的所有设备上使用单个命令安装和启动会很棒.
这样的事情存在吗?
当我从通知中启动它时,我的某个应用程序出现问题.它从未出现在"最近的应用"列表中.
没有通知,每件事都按预期工作:我启动应用程序,导航进入,当我退出它时(使用主页按钮或后退按钮)之后,我可以通过长按主页按钮=>确定返回到它.
当我收到通知时,问题就开始了.如果我从通知启动应用程序,它会启动正确的屏幕,我可以使用app => ok.但是当我退出应用程序(使用主页或后退按钮)时,它不再出现在"最近的应用程序"列表中.更确切地说:
下面是我在状态栏中添加通知的原始代码:
mNotification = new Notification(R.drawable.ic_notif, message, System.currentTimeMillis());
mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(link));
notificationIntent.putExtra(...);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
mNotification.setLatestEventInfo(context, context.getString(R.string.app_name), message, contentIntent);
notificationManager.notify(ConfigApp.NOTIFICATION_ID, mNotification);
Run Code Online (Sandbox Code Playgroud)
我尝试添加FLAG_ACTIVITY_NEW_TASK但它没有帮助:
Intent notificationIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(link));
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.putExtra(...);
Run Code Online (Sandbox Code Playgroud)
通知启动的活动的清单声明:
<activity
android:name=".activity.ActivityMessages"
android:label=""
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="hostapp"
android:pathPrefix="/prefixapp"
android:scheme="schemeapp" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
有人知道如何在通知启动后将应用程序保留在"最近的应用程序"列表中吗?
我在我的一个应用程序中遇到了使用webview显示的问题.
当我调用loadData时,webview首先显示文本,然后加载页面的图像(标准行为).
有时,如果这些图像修改了文本位置,则不会清除旧文本位置,并且会显示旧文本和新文本+图像
这里是问题发生时的截图:

这就像webview没有正确地重绘它的内容.当然一个简单的invalidate()不起作用......
它不会经常发生,但可以说超过20次.
用于显示数据的代码(称为外部Activity生命周期方法):
// Include the html headers to the content received from WS
String webtext = String.format(ConfigApp.HTML_BODY, wsdata.getText());
mWebView.setWebChromeClient(...);
mWebView.setWebViewClient(...);
mWebView.setBackgroundColor(0);
mWebView.loadDataWithBaseURL(null, webtext, "text/html", "UTF-8", null);
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题吗?
我在我的应用程序中设置了一个操作栏.我通过调用Activity.getActionBar()来获取ActionBar .然后我通过ActionBar.addTab()和ActionBar.newTab()方法设置我需要的所有选项卡.
当我处于横向模式时,我的所有类别都显示在屏幕上(即,用户可以看到所有可用的选项卡).我选择了最后一个类别(在屏幕右侧).屏幕旋转后(我现在处于纵向模式),由于ActionBar.setSelectedNavigationItem()方法,我保存了所选类别并将其恢复到我的ActionBar上.
虽然Tab在ActionBar中被很好地选中(即,其标签带有下划线/突出显示),但是当前在屏幕上看不到所考虑的选项卡.实际上,屏幕宽度很小,以显示ActionBar的所有可用选项卡.
我的问题是,setSelectedNavigationItem不要让ActionBar滚动到选定的选项卡,以便用户可以看到它的标签.用户必须手动滚动到ActionBar以显示当前选择的Tab.
有人可以帮我解决这个问题吗?
我在排球上使用以下代码进行字符串请求
pDialog = new ProgressDialog(context);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
pDialog.show();
StringRequest strReq = new StringRequest(Method.POST,
url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
pDialog.dismiss();
Log.e(tag, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pDialog.dismiss();
}
}) {
protected Map<String, String> getParams(){
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "SHOW_FILE");
params.put("filename",filename);
return params;
};
};
// Adding request to request queue
Application.getInstance().addToRequestQueue(strReq, "get_file");
Run Code Online (Sandbox Code Playgroud)
如果变量filename = null,我收到以下错误:
08-02 10:28:06.192: E/Volley(2935): [2128] NetworkDispatcher.run: Unhandled exception java.lang.NullPointerException
08-02 10:28:06.192: …Run Code Online (Sandbox Code Playgroud) 我的Activity的方向更改遇到内存泄漏问题.使用android工具和Memory Analysis Perspective(http://ttlnews.blogspot.com/2010/01/attacking-memory-problems-on-android.html),我终于发现了以下问题:
在方向更改期间,我将所需的数据保存到Inner类中,如下面的代码所示:
public class TestOrientation extends Activity {
private ActivityData mData;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
...
mData = (ActivityData) getLastNonConfigurationInstance();
...
}
@Override
public Object onRetainNonConfigurationInstance() {
return new ActivityData(dataToSave1, dataToSave2);
}
private class ActivityData {
public int mDataToSave1;
public String mDataToSave2;
public ActivityData(int dataToSave1, String dataToSave2) {
mDataToSave1 = dataToSave1;
mDataToSave2 = dataToSave2;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在内存内存分析透视中,我可以看到属性mData保持对活动上下文的引用,因此它永远不会被释放.在几个方向更改后,我有一个递归参考:

为了解决这个问题,我已将ActivityData声明为一个单独的文件,但如果有人能解释我为什么会遇到这个问题,我会很棒!