-2

I have this code snippet:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;

            if (currentapiVersion < Build.VERSION_CODES.JELLY_BEAN) {
                Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
                ComponentName cName = new ComponentName("com.android.phone", "com.android.phone.Settings");
                intent.setComponent(cName);

            } else {
                Intent intent = new Intent();
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setAction(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS);
                context.startActivity(intent);
            }

Why doesn't this work on my android phone (api level 15) , but when I replace it with the code below, it works fine?

                Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
                ComponentName cName = new ComponentName("com.android.phone", "com.android.phone.Settings");
                intent.setComponent(cName);
alfakaiwmega
  • 71
  • 1
  • 1
  • 7

2 Answers2

0

if (currentapiVersion < Build.VERSION_CODES.JELLY_BEAN) {

            Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);

            ComponentName cName = new ComponentName("com.android.phone", "com.android.phone.Settings");

            intent.setComponent(cName); 

            context.startActivity(intent);


        } else {

            Intent intent = new Intent();

            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

         intent.setAction(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS);
            context.startActivity(intent);
        }
Community
  • 1
  • 1
Nidhin Prathap
  • 696
  • 5
  • 15
0

u didnt call startActivity in if Block that is why issue is occuring

JAAD
  • 12,349
  • 7
  • 36
  • 57