Activity result will be lost when the activity has been recreated. - Android Activity

Android examples for Activity:Activity Feature

Description

Activity result will be lost when the activity has been recreated.

Demo Code


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;

public class Main{
    private static final int REQUEST_CODE = 0;
    /**/*from w w  w .java 2 s.  com*/
     * Activity result will be lost when the activity has been recreated.
     * To be fixed.
     */
    public static void startActivityForResult(
            final FragmentActivity fragmentActivity, Intent intent,
            View view) {
        FragmentManager fm = fragmentActivity.getSupportFragmentManager();
        Fragment tempFragment = TempFragment.newInstance(view.getId());
        fm.beginTransaction().add(tempFragment, tempFragment.toString())
                .commit();
        fm.executePendingTransactions();

        tempFragment.startActivityForResult(intent, REQUEST_CODE);
    }
}

Related Tutorials