0

I have a textview in my sony small app with following attributes set

android:autoLink="web|email|phone"
android:linksClickable="true"

But when I run the app, and click on any phone number in the textview, i get an exception say

E/MessageQueue-JNI﹕ android.util.AndroidRuntimeException: Calling startActivity() from  outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:886)
at android.app.ContextImpl.startActivity(ContextImpl.java:880)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
at android.text.style.URLSpan.onClick(URLSpan.java:62)

Since my app is a Sony Small App, I don't have any activity, it is SmallApplication. Is there a way I can fix this issue ?

Thanks

1 Answers1

0

As noted above FLAG_ACTIVITY_NEW_TASK flag is needed to start activity from Small App. You can see startActivity() is called at line #62 of URLSpan class in the error message.

One possible solution is to modify URLSpan class to call startActivity() with FLAG_ACTIVITY_NEW_TASK and use modified URLSpan for TextView.

For example,

  1. Create new customized URLSpan class by extending URLSpan class and overriding onClick() method to call startActivity() with FLAG_ACTIVITY_NEW_TASK.
  2. Create SpannableString for auto link text and set customized URLSpan by SpannableString.setSpan() method.
  3. Set above SpannableString to TextView
mldeveloper
  • 2,253
  • 1
  • 13
  • 14