我正在开发一个针对2.x和3.0设备的Android应用程序,因此我正在使用compatiblebilty API.我在Android 2.0上测试.
我正在尝试将显示的片段替换为另一个片段(搜索结果与搜索结果一起),并且当显示第二个(结果)片段时,我遇到了方向更改的崩溃.
基本上,我有一个活动,包括在布局xml中定义的片段
<fragment class="org.prevoz.android.search.SearchFormFragment"
android:id = "@+id/search_form_fragment"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent" />
Run Code Online (Sandbox Code Playgroud)
第一个片段(SearchFormFragment)显示为默认值.当用户点击"搜索"按钮时,我将SearchFormFragment替换为SearchResultsFragment,后者运行AsyncTask(这就是我想保留它的原因)
// Show the search results fragment
SearchResultsFragment newSearch = new SearchResultsFragment(from, to, when);
newSearch.setRetainInstance(true);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
transaction.replace(R.id.search_form_fragment, newSearch);
transaction.addToBackStack(null);
transaction.commit();
Run Code Online (Sandbox Code Playgroud)
但是,当显示SearchFormFragment并更改方向时,我的应用程序崩溃了
ERROR/AndroidRuntime(334): FATAL EXCEPTION: main
ERROR/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.prevoz.android/org.prevoz.android.search.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
ERROR/AndroidRuntime(334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
ERROR/AndroidRuntime(334): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
ERROR/AndroidRuntime(334): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3815)
ERROR/AndroidRuntime(334): at android.app.ActivityThread.access$2400(ActivityThread.java:125)
ERROR/AndroidRuntime(334): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037)
ERROR/AndroidRuntime(334): …Run Code Online (Sandbox Code Playgroud) android backwards-compatibility screen-orientation android-2.2-froyo
ArrayAdapter.add()方法对我不起作用.我正在使用Eclipse Helios 3.6和ADT插件,Target Source是一个Froyo 2.2模拟器和2.2 HTC Evo 4g.这是我的java类
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[] entries = {"List Item A", "List Item B"};
ArrayAdapter<String> arrAdapt=new ArrayAdapter<String>(this, R.layout.list_item, entries);
arrAdapt.setNotifyOnChange(true);
arrAdapt.add("List Item C");
}
}
Run Code Online (Sandbox Code Playgroud)
这是列表项的布局(list_item.xml)
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:padding="10dp"
android:textSize="12sp"
</TextView>
Run Code Online (Sandbox Code Playgroud)
它给了我和LogCat中的错误
引发者:java.util.AbstractList.add(AbstractList.java:411)中的java.lang.UnsupportedOperationException,位于android.widget.ArrayAdapter.add(ArrayAdapter.java)java.util.AbstractList.add(AbstractList.java:432) :178)
我遇到了与Android ADB Shell相关的问题.当我尝试执行命令chmod时,他给了我一个"坏模式".我不明白为什么.我确定我正在"su"下执行,由'#'表示.任何人都知道为什么会这样,以及如何使它工作?提前致谢.
chmod o+rw /dev/ttyS1
我工作的一个应用程序,它可以运行在Froyo和JellyBean.我有一个扩展PageTransformer的类,如下所示:
import android.support.v4.view.ViewPager.PageTransformer;
import android.view.View;
public class ZoomOutPageTransformer implements PageTransformer {
private static float MIN_SCALE = 0.85f;
private static float MIN_ALPHA = 0.5f;
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();
if (position < -1) {
view.setAlpha(0);
} else if (position <= 1) {
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
float horzMargin = pageWidth * (1 - scaleFactor) …Run Code Online (Sandbox Code Playgroud) 我想在Android应用程序中使用Geocoder,我有以下代码来对其进行采样:
public class LocatorGeo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Geocoder geo = new Geocoder(getApplicationContext());
List<Address> myAddrs = new ArrayList<Address>();
try {
myAddrs = geo.getFromLocationName("CO100AR", 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我得到以下堆栈跟踪:
09-01 15:52:38.809: WARN/System.err(334): java.io.IOException: Service not Available
09-01 15:52:38.819: WARN/System.err(334): at android.location.Geocoder.getFromLocationName(Geocoder.java:159)
09-01 15:52:38.829: WARN/System.err(334): at com.jameselsey.LocatorGeo.onCreate(LocatorGeo.java:25)
09-01 15:52:38.829: WARN/System.err(334): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-01 15:52:38.839: WARN/System.err(334): …Run Code Online (Sandbox Code Playgroud) 我试图将JQuery文件包含在资产/脚本和Internet上,但是警告对话框没有显示.我得到了日志输出并使其成为output.html,它在Windows中工作(太奇怪了!).WebView有什么问题?
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webView);
final String s = "<html><head>" +
"<link href=\"css/my.css\" type=\"text/css\" rel=\"stylesheet\" />" +
"<script src=\"scripts/jquery-1.6.2.min.js\" rel=\"stylesheet\" type=\"text/javascript\"></script>" +
"<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js\" type=\"text/javascript\"></script>" +
"<script>" +
"$(document).ready(function(){ alert('hello'); });" +
"</script>" +
"</head><body><div>All I hear is raindrops." +
"Falling on the rooftop. Oh baby tell me why you have to go. " +
"Cause this pain I feel you won't go away. And today, " +
"I'm officially missing you.</div></body></html>"; …Run Code Online (Sandbox Code Playgroud) 在android中使用MapView,如何设置默认位置,以便每次加载此应用程序时,它会自动居中/缩放伦敦的位置?
我在Android 2.2设备上的GoogleCloudMessaging.register()调用上收到错误"SERVICE_NOT_AVAILABLE".
我正在编写一个使用新版Google Play服务使用GoogleCloudMessaging的应用.我使用Android网站上提供的指南实现了它,我的源代码包含大量错误检查和处理代码,例如确保安装或更新Google Play服务.GCM注册码还实现了谷歌的指数退避,建议用来处理SERVICE_NOT_AVAILABLE错误.
我已经在各种设备上测试了我的应用程序,包括ICS,JB,Honey Comb甚至2.3.x设备.GCM注册工作,我可以通过GCM向它发送消息.但是在2.2设备上,我在GoogleCloudMessaging.register()调用中不断收到SERVICE_NOT_AVAILABLE错误,即使有指数退避也是如此.
GCM失败的设备确实是三星SGH-I896,手机上有2个谷歌帐户.我已经读过这个错误可能是由错误配置的时间引起的,但是时间设置为自动的.这款手机没有上线,正在运行三星股票ROM.
我也试过重新启动设备以及重新安装Google Play服务而没有运气.任何有关此问题的帮助将不胜感激.
编辑:我尝试使用旧的gcm.jar和GCMRegistrar实现GCM,它最终在设备上工作.但是我几乎不认为这是一个很好的解决方案,因为谷歌已经停止支持这种方法了.
编辑2:看到接受的答案.
android android-2.2-froyo google-cloud-messaging google-play-services service-not-available