Reputation: 6081
I've got the following problem. I wrote an app, that works improperly when I specify an min and max sdk-version in the android manifest file. I didn't originally write this into the android manifest-file. It was Eclipse who did it (which was correct, because I wanted to have 11 as a min sdk-version).
So this is what I have in my android manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.T1000flies"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.T1000flies.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Now when I remove the following part:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
the app works without any problems. But when it is in it crashes. I want to use the action bar which requires Android SDK of 11, so I kind of need it to be there. What could be the causing problem?
What I mean by it doesn't work is that it doesn't display data. Even when I just add a TextView to the layout it doesn't work. I'm adding a TextView like this
TextView test = new TextView(this);
test.setText("Test");
LinearLayout layout = new LinearLayout(this);
layout.addView(test);
The app only shows the string "Test" when I remove the uses-sdk part. What could be the problem?
Also, when I rightclick the project and go to Properties-Android only Android 4.3 is ticked. Is that correct? 4.3 is API Level 18 so the targetSDkversion I specified. Does it maybe not work, because I'm trying it on a mobile phone that has API level 16?I removed the android:targetSdkVersion="18"
for once to try out if that may be the problem, but it doesn't fix it. Now I only have android:minSdkVersion="11"
This is the exception I'm getting in LogCat
10-02 15:35:16.350: I/System.out(26656): XML Parsing Excpetion = android.os.NetworkOnMainThreadException
Upvotes: 1
Views: 1317
Reputation: 152867
API level 11 introduced helpful check for network operations in the UI thread, throwing android.os.NetworkOnMainThreadException
. To correctly fix that, do your network operations in a background thread by using e.g. an AsyncTask
. See the question How to fix android.os.NetworkOnMainThreadException? for more.
When you omit the targetSdkVersion
in the manifest, it defaults to minSdkVersion
and if that is omitted too, both default to 1. To maintain backwards compatibility, new API features such as API level 11 network on main thread checking are only enabled for apps that support the API level by specifying an equal or higher target SDK version.
Upvotes: 3