Вопрос

When I call startActivityForResult (or startActivity) the "onCreate" of the MainActivity is being called even before the new activity is created. It doesn't happen with other intents.

This is the code inside click handler of a button in a listview that has an adapter (inside a fragment inside a tab of SherlockActionBar):

            ((MainActivity)context).setVideoId(v.getTag().toString());
            Intent videoIntent = YouTubeStandalonePlayer.createVideoIntent((Activity) context, "AIzaSyC1sF6kq9hHGrQvRSiU8Ks5iYfVCbdg7zA", v.getTag().toString(), 0, true, false);
            ((Activity)context).startActivityForResult(videoIntent, 12);

and this is the constructor of the adapter:

    public ItemAdapter(Context c, int textViewResourceId) {
    super(c, textViewResourceId);
    this.layoutResourceId = textViewResourceId;
    this.context = c;
Это было полезно?

Решение

It's happened because activity change orientation. Add this in the manifest:

<activity
android:configChanges="orientation|screenSize|keyboardHidden"
...
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top