0

好吧,我一直在研究Android应用程序一段时间。它基本上是一个RSS接收器。我使用RSS来检查新闻,天气预报,电视节目表和星座运势。Android应用程序工作在2.3但不在4.0

当我在Android 2.3.3,2.3.6甚至2.1上测试时,一切都很好;但是当我将它发送给拥有Android 4.0的朋友时,它不起作用。我很怀疑,所以我在模拟器上测试了它。也不4.0或4.1仿真器可以运行它。在这里,我提供了Manifest和一个班级。如果有人知道如何解决这个问题,那会很好。

<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。我不知道什么是错的..所以如果有人知道,请帮助..

+1

您能否提供更多信息?有没有可以提供的logcat?你看到什么错误?它安装失败吗?第一次运行时是否会崩溃? –

+0

它被安装吗?你在logcat中看到任何错误吗? –

+0

“它不工作”?这甚至意味着什么? – njzk2

回答

1

从Android 3.x和谷歌已添加一些检查,如果您的应用程序使用非常不好的做法会产生错误。
如果没有日志,很难确认,但最可能的情况是您在活动的核心中进行网络操作,生成NetworkOnUIThread异常。
它不是Android框架中的错误。问题在于你的活动在主线程中运行,即UI线程。
因此,当您在活动中进行网络通话时,整个用户界面将冻结,直到您获得答案(或超时);这是你绝对想要避免的。 这个问题的一个简单的解决方案是使用AsyncTask:这是一个很容易实现的内置解决方案在辅助线程中进行操作。

+0

嘿,谢谢你的回应。请看看这个:[http://stackoverflow.com/questions/12963646/android-app-cant-start-on-android-4-0](http://stackoverflow.com/questions/12963646/android-app -cant-start-on-android-4-0)...我在这个问题中增加了更多信息。日志和更多类 – Igx33

相关问题