在片段和活动完成时未调用onActivityResult()

时间:2014-06-26 09:06:19

标签: android android-fragments

我在活动中有一个片段,我使用一个按钮来使用铃声选择器选择通知声音:

selectSound.setOnClickListener(new OnClickListener() {          
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
            if (notification != null) {
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) notification);
            }
            Log.v("TASKS", "Starting Ringtone picker for reminders");

            startActivityForResult(intent, 5001);
        }
    });

这是片段中的onActivityResult:

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.v("TASKS", "onActivityResult in ReminderSettings: " + requestCode);
    if (resultCode == Activity.RESULT_OK && requestCode == 5001)
    {
        Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

        SharedPreferences settings =
            mActivity.getSharedPreferences("SETTINGS", Context.MODE_PRIVATE);
        Editor editor = settings.edit();

        if (uri != null)
        {
            editor.putString("NOTIFICATION_SOUND", uri.toString());
        }
        else
        {
            editor.putString("NOTIFICATION_SOUND", null);
        }
        editor.commit();
    }

}

我的活动有一个onActivityResult,但它会调用未处理的结果:

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

奇怪的是,在启动并选择铃声后,片段中的onActivityResult或调试时调用活动并且活动似乎完成 - Logcat上没有强制关闭或异常。我现在已经在2个不同的设备上对此进行了测试,并得到了相同的结果 - 如果相关,我会使用ActionBarSherlock作为片段。

0 个答案:

没有答案