2

I'm calling call activity from my adapter but getting below error -

11-29 13:10:41.193: E/AndroidRuntime(12623): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

code -

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+mMobileList.get(position)));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
((Activity)mContext).startActivity(callIntent);

I have added FLAG_ACTIVITY_NEW_TASK also.Still getting error.How to resolve it?

yuva ツ
  • 3,707
  • 9
  • 50
  • 78
  • does your error changed when you added that Flag? – Arash GM Nov 29 '14 at 07:46
  • see this might help: http://stackoverflow.com/q/4197135/3879470 – Mohammed Ali Nov 29 '14 at 08:29
  • @MohammedAli No use.. – yuva ツ Nov 29 '14 at 09:09
  • @yuvaツ is there any problem if u do it in `Activity` like [`this approach`](http://stackoverflow.com/questions/27104124/my-adapter-id-not-changes-while-notifydatasetchanged-also/27119122#27119122) instead of creating alert dialog use `intent` for call and don't need to `setFlag` – Kaushik Nov 29 '14 at 12:11
  • no. i'm displaying contacts in list view phone no. and email id.and want to perform operations on click of them – yuva ツ Nov 29 '14 at 12:20

2 Answers2

1

use this code

Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");
dial.setData(Uri.parse("tel:"+strPhone1));
startActivity(dial);
Kaushik
  • 6,150
  • 5
  • 39
  • 54
Sakshi
  • 151
  • 7
0
<uses-permission android:name="android.permission.CALL_PHONE" />
Digvesh Patel
  • 6,503
  • 1
  • 20
  • 34