简体   繁体   English

Android应用程序只能在2.3上运行,而不能在4.0上运行

[英]Android app working on 2.3 but not on 4.0

Ok, I have been working on a Android application for a while. 好的,我从事Android应用程序已有一段时间了。 It's basicaly a RSS reciever. 基本上是RSS接收者。 I use RSS to check the news, weather forecast, TV schedule and Horoscope. 我使用RSS检查新闻,天气预报,电视时间表和星座运势。

Everything was fine while I was testing it on Android 2.3.3, 2.3.6 and even on 2.1; 当我在Android 2.3.3、2.3.6甚至2.1上进行测试时,一切都很好。 but when I sent it to my friend who has Android 4.0 it did not work. 但是当我将其发送给装有Android 4.0的朋友时,它无法正常工作。 I was suspicious so I tested it on emulator. 我可疑,所以我在模拟器上进行了测试。 Nor 4.0, nor 4.1 Emulators can run it. 也不是4.0和4.1仿真器都可以运行它。 Here I provide Manifest and one class. 在这里,我提供清单和一个类。 If anybody knows how to fix this, that will be great. 如果有人知道如何解决此问题,那将很棒。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="XXX.XXXXX.XXX"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="14" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Vodic"
        android:label="@string/title_activity_pocetna" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".Pomoc"
        android:label="@string/m_tel_vodi_za_odlu_ne"
        ></activity>
    <activity
        android:name=".Pomocna"
        android:label="@string/m_tel_vodi_za_odlu_ne"
        ></activity>
    .
    .
    .

    <activity
        android:name=".TvRasporedTreca"
        android:label="@string/m_tel_vodi_za_odlu_ne"
        ></activity>

</application>

<uses-permission android:name="android.permission.INTERNET" />

<!-- Needed to check when the network connection changes -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

</manifest>

And here's one class: 这是一堂课:

public class Vodic extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pocetna);
    Button tv = (Button)findViewById(R.id.tv);
    Button vijesti = (Button)findViewById(R.id.vijesti);
    Button horoskop = (Button)findViewById(R.id.horoskop);
    Button vremenska_prognoza = (Button)findViewById(R.id.vremenska_prognoza);
    Button o_aplikaciji = (Button)findViewById(R.id.o_aplikaciji);
    Button pomoc = (Button)findViewById(R.id.pomoc);

    tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent fy=new Intent(getApplicationContext(), TV_Raspored.class);
            startActivity(fy);
        }
    });

    .
    .
    .

    pomoc.setOnClickListener(new View.OnClickListener() {
        @Override
    public void onClick(View arg0) {
            Intent fy=new Intent(getApplicationContext(), Pomoc.class);
            startActivity(fy);
        }
    });

}

public boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if(netInfo != null && netInfo.isConnected()) {
        return true;
    }
    return false;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_pocetna, menu);
    return true;
}
}

So, to sum up. 因此,总结一下。 It works on 2.1 and 2.3.3 but doesn't on 4.0 and 4.1 . 它适用于2.1和2.3.3,但不适用于4.0和4.1。 I have no Idea what's wrong.. so if anybody knows, please help.. 我不知道怎么了..所以如果有人知道,请帮忙..

From Android 3.x and onward Google has added some checks that generate errors if your application employs very bad practices. 从Android 3.x及更高版本开始,Google添加了一些检查,如果您的应用程序采用了非常差的做法,这些检查会产生错误。
Without a log it is hard to confirm, but the most likely scenario is that you are making network operations in the core of your activities, generating a NetworkOnUIThread exception. 没有日志很难确认,但是最有可能的情况是,您将网络操作作为活动的核心,从而生成NetworkOnUIThread异常。
It is NOT a bug in the Android framework. 这不是Android框架中的错误。 The problem is that your activities run in the main thread, ie the UI thread. 问题是您的活动在主线程(即UI线程)中运行。
So when you make a network call in an Activity, the whole UI freezes until you get an answer (or a timeout); 因此,当您在“活动”中进行网络通话时,整个UI都会冻结,直到您得到答案(或超时)为止; which is something that you absolutely want to avoid. 这是您绝对要避免的事情。 An easy solution to this issue is to use AsyncTask : it is an easy to implement built-in solutions to make operations in a secondary thread. 解决此问题的一个简单方法是使用AsyncTask :很容易实现内置的解决方案以在辅助线程中进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序在Android 4.0上崩溃,但不是2.3 - 奇怪的异常 - App Crashes on Android 4.0, but not 2.3 — Strange Exception 我的应用在Android 2.3中崩溃,但在4.0中没有崩溃 - My app crashes in Android 2.3 but not in 4.0 AudioSource.VOICE_CALL在android 4.0中无效,但在android 2.3中工作 - AudioSource.VOICE_CALL not working in android 4.0 but working in android 2.3 ActionBar - Android平板电脑2.3和4.0 - ActionBar - Android Tablet 2.3 and 4.0 android:ContentResolver在4.0上有效,但在2.3上无效 - android: ContentResolver works on 4.0 but not on 2.3 Android代码可在2.3上使用,但不能在4.0上使用 - Android Code Works On 2.3 But Not On 4.0 在Android 2.3和Android 4.0上联系photo uri - Contacts photo uri on Android 2.3 and Android 4.0 在Android 2.3和Android 4.0中接收短信 - Receive SMS in Android 2.3 vs Android 4.0 android对话框泄漏窗口在android 4.0中但不是在2.3中 - android dialog leaking window in android 4.0 but not in 2.3 webview在android 2.3上运行良好时显示android 4.0的白屏 - webview is showing white screen for android 4.0 while it is working well on android 2.3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM