Ok, I have been working on a Android application for a while. It's basicaly a RSS reciever. I use RSS to check the news, weather forecast, TV schedule and Horoscope.
Everything was fine while I was testing it on Android 2.3.3, 2.3.6 and even on 2.1; but when I sent it to my friend who has Android 4.0 it did not work. I was suspicious so I tested it on emulator. Nor 4.0, nor 4.1 Emulators can run it. 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 . 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.
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.
It is NOT a bug in the Android framework. The problem is that your activities run in the main thread, ie the UI thread.
So when you make a network call in an Activity, the whole UI freezes until you get an answer (or a timeout); 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.