Jump to content

[Résolu] onConfigurationChanged et onCreate sous ICS


BapNesS

Recommended Posts

Bonjour,

J'ai cherché toute la soirée une réponse à cette question : pourquoi mon activité est recréée alors que je semble avoir convenablement rédigé mon code pour que celui-ci passe dans la fonction onConfigurationchanged et non onCreate lors du passage de l'activity de portrait à paysage (et vise versa) ?

Grosso modo :

Code :

public class AddUsersActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.addusers);
getActionBar().setDisplayHomeAsUpEnabled(true);

mRing = new Ring(new ArrayList<People>());
setRingPrefs();

mList = (ListView) findViewById(R.id.addusers_list);
mList.setAdapter( new AddUsersAdapter(this) );

Log.i("Activity", "onCreate() was called.");
}

@Override
public void onConfigurationchanged(Configuration newConfig) {
super.onConfigurationchanged(newConfig);
Log.i("Activity", "onConfigurationchanged was called.");
}
}

Manifest :


<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
…
<activity
android:name=".activity.AddUsersActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/title_activity_home">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="HomeActivity" />
</activity>

Log :

08-22 23:42:27.561: I/System.out(9028): Creation de l'engrenage

08-22 23:42:27.577: I/Activity(9028): onCreate() was called.
08-22 23:42:27.577: I/Activity(9028): onresume() was called.
*Roration*
08-22 23:42:29.967: I/Activity(9028): onpause() was called.
08-22 23:42:29.975: I/Activity(9028): onSaveInstanceState() was called.
08-22 23:42:29.975: I/Activity(9028): onstop() was called.
08-22 23:42:30.045: I/Activity(9028): onCreate() was called.
08-22 23:42:30.053: I/Activity(9028): onresume() was called.

Une idée ? Merci bien!

Solution :

En ajoutant "screenSize|smallestScreenSize" dans le manifest, cela fonctionne. Personnellement j'ai mis

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"

Cela semble être un pré-requis depuis le SDK ICS.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...