Example usage for android.content Intent getParcelableArrayListExtra

List of usage examples for android.content Intent getParcelableArrayListExtra

Introduction

In this page you can find the example usage for android.content Intent getParcelableArrayListExtra.

Prototype

public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:de.azapps.mirakel.main_activity.MainActivity.java

private void addFilesForTask(final Task t, final Intent intent) {
    final String action = intent.getAction();
    final String type = intent.getType();
    this.currentPosition = getTaskFragmentPosition();
    if (Intent.ACTION_SEND.equals(action) && (type != null)) {
        final Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        t.addFile(this, uri);
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && (type != null)) {
        final List<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        for (final Uri uri : imageUris) {
            t.addFile(this, uri);
        }/*from ww  w.j  a va 2 s . co  m*/
    }
}

From source file:org.kde.kdeconnect.Plugins.SharePlugin.ShareActivity.java

private void updateComputerList() {

    final Intent intent = getIntent();

    String action = intent.getAction();
    if (!Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        finish();// w w  w. j a  va2  s.  co  m
        return;
    }

    BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
        @Override
        public void onServiceStart(final BackgroundService service) {

            Collection<Device> devices = service.getDevices().values();
            final ArrayList<Device> devicesList = new ArrayList<>();
            final ArrayList<ListAdapter.Item> items = new ArrayList<>();

            items.add(new SectionItem(getString(R.string.share_to)));

            for (Device d : devices) {
                if (d.isReachable() && d.isPaired()) {
                    devicesList.add(d);
                    items.add(new EntryItem(d.getName()));
                }
            }

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ListView list = (ListView) findViewById(R.id.listView1);
                    list.setAdapter(new ListAdapter(ShareActivity.this, items));
                    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                            Device device = devicesList.get(i - 1); //NOTE: -1 because of the title!

                            Bundle extras = intent.getExtras();
                            if (extras != null) {
                                if (extras.containsKey(Intent.EXTRA_STREAM)) {

                                    try {

                                        ArrayList<Uri> uriList;
                                        if (!Intent.ACTION_SEND.equals(intent.getAction())) {
                                            uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                                        } else {
                                            Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
                                            uriList = new ArrayList<>();
                                            uriList.add(uri);
                                        }

                                        SharePlugin.queuedSendUriList(getApplicationContext(), device, uriList);

                                    } catch (Exception e) {
                                        Log.e("ShareActivity", "Exception");
                                        e.printStackTrace();
                                    }

                                } else if (extras.containsKey(Intent.EXTRA_TEXT)) {
                                    String text = extras.getString(Intent.EXTRA_TEXT);
                                    String subject = extras.getString(Intent.EXTRA_SUBJECT);

                                    //Hack: Detect shared youtube videos, so we can open them in the browser instead of as text
                                    if (subject != null && subject.endsWith("YouTube")) {
                                        int index = text.indexOf(": http://youtu.be/");
                                        if (index > 0) {
                                            text = text.substring(index + 2); //Skip ": "
                                        }
                                    }

                                    boolean isUrl;
                                    try {
                                        new URL(text);
                                        isUrl = true;
                                    } catch (Exception e) {
                                        isUrl = false;
                                    }
                                    NetworkPackage np = new NetworkPackage(
                                            SharePlugin.PACKAGE_TYPE_SHARE_REQUEST);
                                    if (isUrl) {
                                        np.set("url", text);
                                    } else {
                                        np.set("text", text);
                                    }
                                    device.sendPackage(np);
                                }
                            }
                            finish();
                        }
                    });
                }
            });

        }
    });
}

From source file:nz.ac.otago.psyanlab.common.designer.ExperimentDesignerActivity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_EDIT_STAGE: {
        switch (resultCode) {
        case RESULT_OK:
            ArrayList<PropIdPair> props = data.getParcelableArrayListExtra(Args.EXPERIMENT_PROPS);
            long sceneId = data.getLongExtra(Args.SCENE_ID, -1);

            int height = data.getIntExtra(Args.STAGE_HEIGHT, -1);
            int width = data.getIntExtra(Args.STAGE_WIDTH, -1);
            int orientation = data.getIntExtra(Args.STAGE_ORIENTATION, Scene.ORIENTATION_LANDSCAPE);

            updateStageInScene(sceneId, props, orientation, width, height);
            break;

        default:/*from   w  w w  .  j  a  v  a2 s .  co m*/
            break;
        }
        break;
    }
    case REQUEST_ASSET_IMPORT: {
        switch (resultCode) {
        case RESULT_OK:
            String[] paths = data.getStringArrayExtra(Args.PICKED_PATHS);
            Time t = new Time();
            t.setToNow();
            mExperiment.assets.put(ModelUtils.findUnusedKey(mExperiment.assets),
                    Asset.getFactory().newAsset(paths[0]));
            mAssetAdapter.notifyDataSetChanged();
            break;
        default:
            break;
        }
        break;
    }
    case REQUEST_SOURCE_IMPORT: {
        switch (resultCode) {
        case RESULT_OK:
            String[] paths = data.getStringArrayExtra(Args.PICKED_PATHS);
            Time t = new Time();
            t.setToNow();
            Source newSource = new Source();
            newSource.setExternalFile(new File(paths[0]));
            mExperiment.sources.put(ModelUtils.findUnusedKey(mExperiment.sources), newSource);
            mSourceAdapter.notifyDataSetChanged();
            break;
        default:
            break;
        }
    }
    default:
        break;
    }
}

From source file:com.igniva.filemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;/* w  ww  . j  ava  2s  .  c  o m*/
    path = i.getStringExtra("path");
    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                Main m = ((Main) getFragment().getTab());
                m.loadlist(path, false, 0);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra("failedOps") != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra("failedOps");
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if ((openprocesses = i.getBooleanExtra("openprocesses", false))) {

        android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer());
        //   transaction.addToBackStack(null);
        select = 102;
        openprocesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null)
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {

            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }
}

From source file:com.amaze.filemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;/*from  w ww .  ja va2s  .  c o m*/
    path = i.getStringExtra("path");
    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                Main m = ((Main) getFragment().getTab());
                m.loadlist(path, false, 0);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra("failedOps") != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra("failedOps");
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if ((openprocesses = i.getBooleanExtra("openprocesses", false))) {

        android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer());
        //   transaction.addToBackStack(null);
        select = 102;
        openprocesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null)
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {

            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {

            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }
}

From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java

@Override
public void onActivityResult(final int reqCode, int resultCode, Intent data) {
    Log.i(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data);
    super.onActivityResult(reqCode, resultCode, data);

    if ((data == null && reqCode != TAKE_PHOTO && reqCode != SMS_DEFAULT)
            || (resultCode != RESULT_OK && reqCode != SMS_DEFAULT)) {
        updateLinkPreviewState();/*from  ww  w . j a  v a 2s .c o m*/
        return;
    }

    switch (reqCode) {
    case PICK_DOCUMENT:
        setMedia(data.getData(), MediaType.DOCUMENT);
        break;
    case PICK_AUDIO:
        setMedia(data.getData(), MediaType.AUDIO);
        break;
    case PICK_CONTACT:
        if (isSecureText && !isSmsForced()) {
            openContactShareEditor(data.getData());
        } else {
            addAttachmentContactInfo(data.getData());
        }
        break;
    case GET_CONTACT_DETAILS:
        sendSharedContact(data.getParcelableArrayListExtra(ContactShareEditActivity.KEY_CONTACTS));
        break;
    case GROUP_EDIT:
        recipient = Recipient.from(this, data.getParcelableExtra(GroupCreateActivity.GROUP_ADDRESS_EXTRA),
                true);
        recipient.addListener(this);
        titleView.setTitle(glideRequests, recipient);
        NotificationChannels.updateContactChannelName(this, recipient);
        setBlockedUserState(recipient, isSecureText, isDefaultSms);
        supportInvalidateOptionsMenu();
        break;
    case TAKE_PHOTO:
        if (attachmentManager.getCaptureUri() != null) {
            setMedia(attachmentManager.getCaptureUri(), MediaType.IMAGE);
        }
        break;
    case ADD_CONTACT:
        recipient = Recipient.from(this, recipient.getAddress(), true);
        recipient.addListener(this);
        fragment.reloadList();
        break;
    case PICK_LOCATION:
        SignalPlace place = new SignalPlace(PlacePicker.getPlace(data, this));
        attachmentManager.setLocation(place, getCurrentMediaConstraints());
        break;
    case PICK_GIF:
        setMedia(data.getData(), MediaType.GIF, data.getIntExtra(GiphyActivity.EXTRA_WIDTH, 0),
                data.getIntExtra(GiphyActivity.EXTRA_HEIGHT, 0));
        break;
    case SMS_DEFAULT:
        initializeSecurity(isSecureText, isDefaultSms);
        break;
    case MEDIA_SENDER:
        long expiresIn = recipient.getExpireMessages() * 1000L;
        int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
        boolean initiating = threadId == -1;
        TransportOption transport = data.getParcelableExtra(MediaSendActivity.EXTRA_TRANSPORT);
        String message = data.getStringExtra(MediaSendActivity.EXTRA_MESSAGE);
        SlideDeck slideDeck = new SlideDeck();

        if (transport == null) {
            throw new IllegalStateException("Received a null transport from the MediaSendActivity.");
        }

        sendButton.setTransport(transport);

        List<Media> mediaList = data.getParcelableArrayListExtra(MediaSendActivity.EXTRA_MEDIA);

        for (Media mediaItem : mediaList) {
            if (MediaUtil.isVideoType(mediaItem.getMimeType())) {
                slideDeck
                        .addSlide(new VideoSlide(this, mediaItem.getUri(), 0, mediaItem.getCaption().orNull()));
            } else if (MediaUtil.isGif(mediaItem.getMimeType())) {
                slideDeck.addSlide(new GifSlide(this, mediaItem.getUri(), 0, mediaItem.getWidth(),
                        mediaItem.getHeight(), mediaItem.getCaption().orNull()));
            } else if (MediaUtil.isImageType(mediaItem.getMimeType())) {
                slideDeck.addSlide(new ImageSlide(this, mediaItem.getUri(), 0, mediaItem.getWidth(),
                        mediaItem.getHeight(), mediaItem.getCaption().orNull()));
            } else {
                Log.w(TAG,
                        "Asked to send an unexpected mimeType: '" + mediaItem.getMimeType() + "'. Skipping.");
            }
        }

        final Context context = ConversationActivity.this.getApplicationContext();

        sendMediaMessage(transport.isSms(), message, slideDeck, Collections.emptyList(),
                Collections.emptyList(), expiresIn, subscriptionId, initiating)
                        .addListener(new AssertedSuccessListener<Void>() {
                            @Override
                            public void onSuccess(Void result) {
                                AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
                                    Stream.of(slideDeck.getSlides()).map(Slide::getUri).withoutNulls()
                                            .filter(BlobProvider::isAuthority)
                                            .forEach(uri -> BlobProvider.getInstance().delete(context, uri));
                                });
                            }
                        });

        break;
    }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;//from   w w w . j  a v  a 2  s. co  m
    path = i.getStringExtra("path");

    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                MainFragment m = ((MainFragment) getFragment().getTab());
                m.loadlist(path, false, OpenMode.FILE);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS) != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS);
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if (i.getCategories() != null && i.getCategories().contains(CLOUD_AUTHENTICATOR_GDRIVE)) {

        // we used an external authenticator instead of APIs. Probably for Google Drive
        CloudRail.setAuthenticationResponse(intent);

    } else if ((openProcesses = i.getBooleanExtra(KEY_INTENT_PROCESS_VIEWER, false))) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer(), KEY_INTENT_PROCESS_VIEWER);
        //   transaction.addToBackStack(null);
        selectedStorage = SELECT_102;
        openProcesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null) {
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }

        if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
                if (sharedPref.getString(KEY_PREF_OTG, null) == null) {
                    sharedPref.edit().putString(KEY_PREF_OTG, VALUE_PREF_OTG_NULL).apply();
                    refreshDrawer();
                }
            } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
                sharedPref.edit().putString(KEY_PREF_OTG, null).apply();
                refreshDrawer();
            }
        }
    }
}

From source file:org.naturenet.ui.MainActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case (REQUEST_CODE_JOIN): {
        if (resultCode == Activity.RESULT_OK) {
            if (JoinActivity.EXTRA_LAUNCH.equals(data.getExtras().getString(JoinActivity.EXTRA_JOIN))) {
                showLaunchFragment();//from  ww  w. java  2s.c  o m
            } else if (JoinActivity.EXTRA_LOGIN.equals(data.getExtras().getString(JoinActivity.EXTRA_JOIN))) {
                signed_user = data.getParcelableExtra(JoinActivity.EXTRA_NEW_USER);
                logout.setVisible(true);
                settings.setVisible(true);
                this.supportInvalidateOptionsMenu();

                if (signed_user.avatar != null) {
                    NatureNetUtils.showUserAvatar(this, nav_iv, signed_user.avatar);
                }

                display_name.setText(signed_user.displayName);
                mFirebase.child(Site.NODE_NAME).child(signed_user.affiliation).child(NAME)
                        .addListenerForSingleValueEvent(new ValueEventListener() {
                            @Override
                            public void onDataChange(DataSnapshot snapshot) {
                                affiliation.setText((String) snapshot.getValue());
                            }

                            @Override
                            public void onCancelled(DatabaseError databaseError) {
                                Timber.w("Could not get user's affiliation");
                            }
                        });
                sign_in.setVisibility(View.GONE);
                join.setVisibility(View.GONE);
                display_name.setVisibility(View.VISIBLE);
                affiliation.setVisibility(View.VISIBLE);
                goToExploreFragment();
                drawer.openDrawer(GravityCompat.START);
            }
        }
        break;
    }
    case (REQUEST_CODE_LOGIN): {
        if (resultCode == Activity.RESULT_OK) {
            if (data.getStringExtra(LoginActivity.EXTRA_LOGIN).equals(LoginActivity.EXTRA_JOIN)) {
                goToJoinActivity();
            } else {
                drawer.openDrawer(GravityCompat.START);
            }
        }
        break;
    }
    case REQUEST_CODE_CAMERA: {
        if (resultCode == MainActivity.RESULT_OK) {
            Timber.d("Camera Path: %s", cameraPhoto.getPhotoPath());
            selectedImages.add(Uri.fromFile(new File(cameraPhoto.getPhotoPath())));
            cameraPhoto.addToGallery();
            setGallery();
            goToAddObservationActivity(true);
        }
        break;
    }
    case REQUEST_CODE_GALLERY: {
        if (resultCode == MainActivity.RESULT_OK) {
            galleryPhoto.setPhotoUri(data.getData());
            Timber.d("Gallery Path: %s", galleryPhoto.getPath());
            observationPath = Uri.fromFile(new File(galleryPhoto.getPath()));
            setGallery();
            goToAddObservationActivity(false);
        }
        break;
    }
    //This case is for retrieving images from the phone's Gallery app.
    case GALLERY_IMAGES: {
        //First, make sure the the user actually chose something.
        if (data != null) {
            //In this case, the user selected multiple images
            if (data.getClipData() != null) {

                for (int j = 0; j < data.getClipData().getItemCount(); j++) {
                    selectedImages.add(data.getClipData().getItemAt(j).getUri());
                    Log.d("images", "selected image: " + data.getClipData().getItemAt(j).toString());
                }
            }
            //in this case, the user selected just one image
            else if (data.getData() != null) {
                selectedImages.add(data.getData());
            }

            //Here we should have our selected images
            goToAddObservationActivity(false);
        }
        break;
    }
    //This case is for retrieving images from the custom Gallery (phones using api <18).
    case IMAGE_PICKER_RESULTS: {
        if (resultCode == MainActivity.RESULT_OK) {
            selectedImages = data.getParcelableArrayListExtra("images");
            goToAddObservationActivity(false);
        }
        break;
    }
    //Here we just handle the result of the Settings activity which isn't anything but we want to unhighlight it in the menu bar
    case SETTINGS: {
        navigationView.getMenu().findItem(R.id.nav_settings).setChecked(false);
        break;
    }
    }
}

From source file:com.android.mail.compose.ComposeActivity.java

private void finishCreate() {
    final Bundle savedState = mInnerSavedState;
    findViews();//from  w  w w. j  ava2 s  .  c  om
    final Intent intent = getIntent();
    final Message message;
    final ArrayList<AttachmentPreview> previews;
    mShowQuotedText = false;
    final CharSequence quotedText;
    int action;
    // Check for any of the possibly supplied accounts.;
    final Account account;
    if (hadSavedInstanceStateMessage(savedState)) {
        action = savedState.getInt(EXTRA_ACTION, COMPOSE);
        account = savedState.getParcelable(Utils.EXTRA_ACCOUNT);
        message = savedState.getParcelable(EXTRA_MESSAGE);

        previews = savedState.getParcelableArrayList(EXTRA_ATTACHMENT_PREVIEWS);
        mRefMessage = savedState.getParcelable(EXTRA_IN_REFERENCE_TO_MESSAGE);
        quotedText = savedState.getCharSequence(EXTRA_QUOTED_TEXT);

        mExtraValues = savedState.getParcelable(EXTRA_VALUES);

        // Get the draft id from the request id if there is one.
        if (savedState.containsKey(EXTRA_REQUEST_ID)) {
            final int requestId = savedState.getInt(EXTRA_REQUEST_ID);
            if (sRequestMessageIdMap.containsKey(requestId)) {
                synchronized (mDraftLock) {
                    mDraftId = sRequestMessageIdMap.get(requestId);
                }
            }
        }
    } else {
        account = obtainAccount(intent);
        action = intent.getIntExtra(EXTRA_ACTION, COMPOSE);
        // Initialize the message from the message in the intent
        message = intent.getParcelableExtra(ORIGINAL_DRAFT_MESSAGE);
        previews = intent.getParcelableArrayListExtra(EXTRA_ATTACHMENT_PREVIEWS);
        mRefMessage = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE);
        mRefMessageUri = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE_URI);
        quotedText = null;

        if (Analytics.isLoggable()) {
            if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
                Analytics.getInstance().sendEvent("notification_action", "compose", getActionString(action), 0);
            }
        }
    }
    mAttachmentsView.setAttachmentPreviews(previews);

    setAccount(account);
    if (mAccount == null) {
        return;
    }

    initRecipients();

    // Clear the notification and mark the conversation as seen, if necessary
    final Folder notificationFolder = intent.getParcelableExtra(EXTRA_NOTIFICATION_FOLDER);

    if (notificationFolder != null) {
        final Uri conversationUri = intent.getParcelableExtra(EXTRA_NOTIFICATION_CONVERSATION);
        Intent actionIntent;
        if (conversationUri != null) {
            actionIntent = new Intent(MailIntentService.ACTION_RESEND_NOTIFICATIONS_WEAR);
            actionIntent.putExtra(Utils.EXTRA_CONVERSATION, conversationUri);
        } else {
            actionIntent = new Intent(MailIntentService.ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS);
            actionIntent.setData(Utils.appendVersionQueryParameter(this, notificationFolder.folderUri.fullUri));
        }
        actionIntent.setPackage(getPackageName());
        actionIntent.putExtra(Utils.EXTRA_ACCOUNT, account);
        actionIntent.putExtra(Utils.EXTRA_FOLDER, notificationFolder);

        startService(actionIntent);
    }

    if (intent.getBooleanExtra(EXTRA_FROM_EMAIL_TASK, false)) {
        mLaunchedFromEmail = true;
    } else if (Intent.ACTION_SEND.equals(intent.getAction())) {
        final Uri dataUri = intent.getData();
        if (dataUri != null) {
            final String dataScheme = intent.getData().getScheme();
            final String accountScheme = mAccount.composeIntentUri.getScheme();
            mLaunchedFromEmail = TextUtils.equals(dataScheme, accountScheme);
        }
    }

    if (mRefMessageUri != null) {
        mShowQuotedText = true;
        mComposeMode = action;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
            String wearReply = null;
            if (remoteInput != null) {
                LogUtils.d(LOG_TAG, "Got remote input from new api");
                CharSequence input = remoteInput.getCharSequence(NotificationActionUtils.WEAR_REPLY_INPUT);
                if (input != null) {
                    wearReply = input.toString();
                }
            } else {
                // TODO: remove after legacy code has been removed.
                LogUtils.d(LOG_TAG, "No remote input from new api, falling back to compatibility mode");
                ClipData clipData = intent.getClipData();
                if (clipData != null && LEGACY_WEAR_EXTRA.equals(clipData.getDescription().getLabel())) {
                    Bundle extras = clipData.getItemAt(0).getIntent().getExtras();
                    if (extras != null) {
                        wearReply = extras.getString(NotificationActionUtils.WEAR_REPLY_INPUT);
                    }
                }
            }

            if (!TextUtils.isEmpty(wearReply)) {
                createWearReplyTask(this, mRefMessageUri, UIProvider.MESSAGE_PROJECTION, mComposeMode,
                        wearReply).execute();
                finish();
                return;
            } else {
                LogUtils.w(LOG_TAG, "remote input string is null");
            }
        }

        getLoaderManager().initLoader(INIT_DRAFT_USING_REFERENCE_MESSAGE, null, this);
        return;
    } else if (message != null && action != EDIT_DRAFT) {
        initFromDraftMessage(message);
        initQuotedTextFromRefMessage(mRefMessage, action);
        mShowQuotedText = message.appendRefMessageContent;
        // if we should be showing quoted text but mRefMessage is null
        // and we have some quotedText, display that
        if (mShowQuotedText && mRefMessage == null) {
            if (quotedText != null) {
                initQuotedText(quotedText, false /* shouldQuoteText */);
            } else if (mExtraValues != null) {
                initExtraValues(mExtraValues);
                return;
            }
        }
    } else if (action == EDIT_DRAFT) {
        if (message == null) {
            throw new IllegalStateException("Message must not be null to edit draft");
        }
        initFromDraftMessage(message);
        // Update the action to the draft type of the previous draft
        switch (message.draftType) {
        case UIProvider.DraftType.REPLY:
            action = REPLY;
            break;
        case UIProvider.DraftType.REPLY_ALL:
            action = REPLY_ALL;
            break;
        case UIProvider.DraftType.FORWARD:
            action = FORWARD;
            break;
        case UIProvider.DraftType.COMPOSE:
        default:
            action = COMPOSE;
            break;
        }
        LogUtils.d(LOG_TAG, "Previous draft had action type: %d", action);

        mShowQuotedText = message.appendRefMessageContent;
        if (message.refMessageUri != null) {
            // If we're editing an existing draft that was in reference to an existing message,
            // still need to load that original message since we might need to refer to the
            // original sender and recipients if user switches "reply <-> reply-all".
            mRefMessageUri = message.refMessageUri;
            mComposeMode = action;
            getLoaderManager().initLoader(REFERENCE_MESSAGE_LOADER, null, this);
            return;
        }
    } else if ((action == REPLY || action == REPLY_ALL || action == FORWARD)) {
        if (mRefMessage != null) {
            initFromRefMessage(action);
            mShowQuotedText = true;
        }
    } else {
        if (initFromExtras(intent)) {
            return;
        }
    }

    mComposeMode = action;
    finishSetup(action, intent, savedState);
}

From source file:android.app.Activity.java

/**
 * Called when the activity is starting.  This is where most initialization
 * should go: calling {@link #setContentView(int)} to inflate the
 * activity's UI, using {@link #findViewById} to programmatically interact
 * with widgets in the UI, calling/*from w w w . ja va2  s  .  co  m*/
 * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve
 * cursors for data being displayed, etc.
 * 
 * <p>You can call {@link #finish} from within this function, in
 * which case onDestroy() will be immediately called without any of the rest
 * of the activity lifecycle ({@link #onStart}, {@link #onResume},
 * {@link #onPause}, etc) executing.
 * 
 * <p><em>Derived classes must call through to the super class's
 * implementation of this method.  If they do not, an exception will be
 * thrown.</em></p>
 * 
 * @param savedInstanceState If the activity is being re-initialized after
 *     previously being shut down then this Bundle contains the data it most
 *     recently supplied in {@link #onSaveInstanceState}.  <b><i>Note: Otherwise it is null.</i></b>
 * 
 * @see #onStart
 * @see #onSaveInstanceState
 * @see #onRestoreInstanceState
 * @see #onPostCreate
 */
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_LIFECYCLE)
        Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState);
    if (mLastNonConfigurationInstances != null) {
        mAllLoaderManagers = mLastNonConfigurationInstances.loaders;
    }
    if (mActivityInfo.parentActivityName != null) {
        if (mActionBar == null) {
            mEnableDefaultActionBarUp = true;
        } else {
            mActionBar.setDefaultDisplayHomeAsUpEnabled(true);
        }
    }

    if (isAvailable()) {
        /* if this device can use the platform */
        Log.w("MIGRATOR", "This is " + getLocalClassName());
        Intent intent = getIntent();
        Bundle tmpBundle = intent.getBundleExtra("MIGRATED");
        ArrayList<Bundle> stacked = intent.getParcelableArrayListExtra("MIGRATED STACK");
        if (tmpBundle != null) {
            /* true if this Activity was migrated */
            if (stacked != null) {
                /* true if this Activity called next Activity */
                Intent next = new Intent();
                Bundle nextBundle = stacked.get(0);
                next.setClassName(nextBundle.getString("MIGRATED PNAME"),
                        nextBundle.getString("MIGRATED CNAME"));
                next.putExtra("MIGRATED", nextBundle);
                stacked.remove(0);
                int code = tmpBundle.getInt("MIGRATED REQUEST CODE");
                Bundle option = nextBundle.getBundle("MIGRATED REQUEST OPTIONS");
                if (!stacked.isEmpty()) {
                    /* store for next Activity */
                    next.putParcelableArrayListExtra("MIGRATED STACK", stacked);
                }
                Log.w("MIGRATOR", "Start ForResult: code=" + code);
                mReceiverStackFlag = true;
                mStackedNextIntent = next;
                mStackedNextCode = code;
                mStackedNextOption = option;
            } else {
                /* for debug */
                Log.w("MIGRATOR", "stack is null");
            }
            savedInstanceState = null;
            mMigFlag = true;
            migratedState = tmpBundle;
            Intent tmpIntent = tmpBundle.getParcelable("MIGRATED_INTENT");
            if (tmpIntent != null) {
                tmpIntent.setAction(Intent.ACTION_MIGRATE);
                setIntent(tmpIntent);
            }

            /* File handling */
            ArrayList<String> tmpNames = tmpBundle.getStringArrayList("TARGET_FILE_NAME");
            if (tmpNames != null) {
                FileWorker fw = new FileWorker(tmpNames.toArray(new String[tmpNames.size()]),
                        FileWorker.WRITE_MODE);
                fw.start();
                tmpNames = null;
            }
            Log.w("MIGRATOR", "successed migaration: " + tmpBundle.toString());
            tmpBundle = null;
        } else {
            /* for debug */
            Log.w("MIGRATOR", "tmpBundle is null");
        }
    }

    if (savedInstanceState != null) {
        Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG);
        mFragments.restoreAllState(p,
                mLastNonConfigurationInstances != null ? mLastNonConfigurationInstances.fragments : null);
    }
    mFragments.dispatchCreate();
    getApplication().dispatchActivityCreated(this, savedInstanceState);
    mCalled = true;

}