The back button on Android saves the contact, and does not return to the application.

I created an application that uses cordova to create a new contact. To do this, I created a special Cordova plugin, and this is done by running Intent to open the contact creation screen and fill in some of the fields on it. However, when the "Back" button is pressed on this screen, the contact is saved instead of returning to the application. Is this the intended behavior in some way, and is there a way to stop it?

The code that launches the contact creation screen is as follows:

private void createContact(String fullname, String phone, String company) {
    Context context=this.cordova.getActivity().getApplicationContext();
    Intent i = new Intent(Intent.ACTION_INSERT);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
    i.setType(ContactsContract.Contacts.CONTENT_TYPE);
    i.putExtra(ContactsContract.Intents.Insert.NAME, fullname);
    i.putExtra(ContactsContract.Intents.Insert.PHONE, phone);
    i.putExtra(ContactsContract.Intents.Insert.COMPANY, company);
    context.startActivity(i);
}
+4
source share
1 answer

. "".

manifest , , , ContactEditorActivity. ContactEditorFragment, .

,

        View saveMenuItem = customActionBarView.findViewById(R.id.save_menu_item);
        saveMenuItem.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mFragment.doSaveAction();
            }
        });

doSaveAction() Fragment:

public void doSaveAction() {
    save(SaveMode.CLOSE);
}

, , , , onBackPressed() .

@Override
public void onBackPressed() {
    mFragment.save(SaveMode.CLOSE);
}

, , .

. , ( ) , . " " : FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_MULTIPLE_TASK.

FLAG_ACTIVITY_NEW_TASK Android Activity , , (, , ).

+1

Source: https://habr.com/ru/post/1542618/


All Articles