0

我创建了子类,TabActivity它包含四个TabHost选项卡。

我只想从我的应用程序中选择联系人,为此我使用以下代码

private final int PICK = 2;
Intent intentContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); 
    parentActivity.startActivityForResult(intentContact, PICK);

Android Contact Picker 屏幕调用成功,当我点击任何联系人时,它会将我重定向到我调用它的应用程序的最后一个屏幕,但onActivityResult没有调用方法。

在这方面我需要你的帮助。如果我忘记提及任何事情,请告诉我。

4

3 回答 3

1

如您所愿,这里有一些代码内容。

public class MyActivity extends TabActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
            super.onCreate(savedInstanceState);

            // some other stuff

            TabHost.TabSpec firstTab = tabHost.newTabSpec("firstTab");

            firstTab.setContent(new Intent(this, FirstTabActivity.class)); // your class with content picker

            tabHost.addTab(firstTab);
    }
}

这是另一个

public class FirstTabActivity extends Activity
{
    private static final int PICK_REQUEST_CODE = 2;

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

            // some stuff

            Button pickContactButton = findViewById(R.id.btn_pick_contact);

            pickContactButton.setOnClickListener(new View.OnClickListener()
            {
                    @Override
                    public void onClick(View view)
                    {
                            Intent intentContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                            startActivityForResult(intentContact, PICK_REQUEST_CODE);
                    }
            });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
            super.onActivityResult(requestCode, resultCode, data);

            if(PICK_REQUEST_CODE == requestCode && resultCode == RESULT_OK)
            {
                    // do some stuff
            }
    }
}
于 2013-01-02T10:14:09.670 回答
0

其他的做法是这样...

1.On button click(which you want to open intent) open another activity.
2.On another activity's onCreate() open that intent.
3.onActivityResult set static data which is on previous activity and call finish().
4.This way no one ever know that you opened such a activity and you ll get your data.
:)
于 2013-01-02T10:16:32.197 回答
0

TabActivity有几个奇怪的行为,这可能是其中之一,您可以解决它以使其工作,但我绝对建议您开始删除它,自 API 级别 13 以来它已被弃用。阅读有关它的更多信息:(https ://developer.android.com/reference/android/app/TabActivity.html )

于 2013-01-02T08:48:34.807 回答