0

I am using tabs in my code and in one tab I am using startActivityForResult(). Now startActivityForResult() is working but onActivityResult() is not called no matter what I do. Can somebody help me with the problem. I don't know what is the problem actually there is no warning or error. Below is the code

TabActivity:

  TabHost.TabSpec spec = tabHost.newTabSpec(LIST2_TAB_TAG);
    spec.setIndicator("RingTones");
    Intent content = new Intent(this, TestClass.class);
    spec.setContent(content);
    tabHost.addTab(spec);

TestClass:

public class TestClass extends Activity
{

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
   /* intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
                        ("chosenRingtone" ==null) ? (Uri)null :Uri.parse("chosenRingtone"));*/

    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
    this.startActivityForResult(intent, 5);
}

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

    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case 1:
            {
              Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        if (uri != null)
        {
            intent.putExtra("ToneUriI", uri.toString());
        }
        else
        {
           // this.chosenRingtone = null;
        }
                break;
            }
            default: {
                break;
            }
        }
    }
}

I have tried the following solutions but they are of no help.

any help will be appreciated.... :)

Community
  • 1
  • 1
Umair
  • 6,366
  • 15
  • 42
  • 50
  • Look at this specific answer: http://stackoverflow.com/a/9207889/885028 – aga Mar 04 '15 at 14:07
  • @aga I tried it but same result. And also I don't know the reason why this is happening. – Umair Mar 04 '15 at 14:09
  • `this.startActivityForResult(intent, 5);`, your `requestCode` is `5`, in your `onActivityResult` there is no `requestCode` checking for `5` – Xcihnegn Mar 04 '15 at 14:56
  • @Xcihnegn onActivityResult isn't even called then how the condition requestCode == 5 will be run ? – Umair Mar 05 '15 at 07:14
  • Here is a post http://stackoverflow.com/questions/7671637/how-to-set-ringtone-with-ringtonemanager-action-ringtone-picker – Xcihnegn Mar 05 '15 at 10:24

0 Answers0