Reputation: 16534
Is there a way to have a Linkify
'd link call a method in my Activity
or am I only allowed to use Linkify
to create links to other activities / apps etc.?
Upvotes: 3
Views: 2831
Reputation: 11662
It sounds like you've got several pieces of this worked out. The missing piece seems to be having an existing Activity which is in the foreground receive the Intent. You can do that by declaring the Activity to be singleTop in the Manifest (android:launchMode="singleTop"
).
So the workflow looks like:
1) Linkify the text by addLinks with your regex, Linkify.Matcher, and Linkify.TransformFilter
2) Set up a receiver to catch the Intent launched by the clicked link.
3) In the onReceive of the associated BroadcastReceiver, set up an Intent to encapsulate the fact that your link has been clicked. Then call startActivity on the Activity (which is already in the foreground), passing the Intent.
4) In the onResume callback on the Activity, check the Intent to see if the function should be called.
Upvotes: 2
Reputation: 10184
YOu could also just abandon using linkify and just use the regex of linkify to go and attach clickable spans to the places you want. Those clickable spans can call into your code.
Here's an example: Android: Launch activity from clickable text
Upvotes: 2