簡體   English   中英

Android應用程序只能在2.3上運行,而不能在4.0上運行

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

好的,我從事Android應用程序已有一段時間了。 基本上是RSS接收者。 我使用RSS檢查新聞,天氣預報,電視時間表和星座運勢。

當我在Android 2.3.3、2.3.6甚至2.1上進行測試時,一切都很好。 但是當我將其發送給裝有Android 4.0的朋友時,它無法正常工作。 我可疑,所以我在模擬器上進行了測試。 也不是4.0和4.1仿真器都可以運行它。 在這里,我提供清單和一個類。 如果有人知道如何解決此問題,那將很棒。

<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>

這是一堂課:

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;
}
}

因此,總結一下。 它適用於2.1和2.3.3,但不適用於4.0和4.1。 我不知道怎么了..所以如果有人知道,請幫忙..

從Android 3.x及更高版本開始,Google添加了一些檢查,如果您的應用程序采用了非常差的做法,這些檢查會產生錯誤。
沒有日志很難確認,但是最有可能的情況是,您將網絡操作作為活動的核心,從而生成NetworkOnUIThread異常。
這不是Android框架中的錯誤。 問題是您的活動在主線程(即UI線程)中運行。
因此,當您在“活動”中進行網絡通話時,整個UI都會凍結,直到您得到答案(或超時)為止; 這是您絕對要避免的事情。 解決此問題的一個簡單方法是使用AsyncTask :很容易實現內置的解決方案以在輔助線程中進行操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM