html and activity links in TextView

So we need to linkify a TextView.

By linkify, I mean adding links to a TextView. These links could either be html links that link to a webpage, or some url that links to an Activity (launches an activity).

TextView mTextSample = (TextView) findViewById(;
String text = "Visit my blog or run the myactivity callback";

Pattern pattern = Pattern.compile("");
Linkify.addLinks(mTextSample, pattern, "http://");
Pattern pattern2 = Pattern.compile("myactivity");
Linkify.addLinks(mTextSample, pattern2, "sherif-activity://");

Now, the first pattern with the html link to my blogger page will work correctly.

However the second part should startActivity myactivity.
It will not work unless we specify that sherif-activity://myactivity is a callback url for an activity of our package.

So, for this to work and call say TestActivity!
Your TestActivity in AndroidManifest.xml should look like this:

		<data android:host="myactivity" android:scheme="sherif-activity" />
		<action android:name="android.intent.action.VIEW" />
		<category android:name="android.intent.category.DEFAULT" />
		<category android:name="android.intent.category.BROWSABLE" />

Congradulations, you just created a link to your website and to your activity in the same TextView.

How about sending some data to the new activity using the link!?

Lets first investigate the other way of linkifying a TextView. This would be using normal html tags, namely the <a> tag.

TextView mTextSample = (TextView) findViewById(;
String text = "Visit my blog <a href=\"\">mysite</a> or run the <a href=\"sherif-activity://myactivity\">myactivity</a> callback";

This will work perfectly like the previous approach.

Now, let us add some data to the link and ultimately the intent that will open the new activity.
We will use the normal GET parameters to add data.

so will will comment out one line of code which initializes text and change it so some data is added to linked activity.

String text = "Visit my blog <a href=\"\">mysite</a> or run the <a href=\"sherif-activity://myactivity?author=sherif&nick=king\">myactivity</a> callback";
//String text = "Visit my blog <a href=\"\">mysite</a> or run the <a href=\"sherif-activity://myactivity\">myactivity</a> callback";

So How can we retrieve these extra parameters in the TestActivity!? In this case, the parameter author and nick
It is rather simple:

String author = getIntent().getData().getQueryParameter("author");
String nick = getIntent().getData().getQueryParameter("nick");

Click here for Sample Project + Source Code (download) 


  1. Thank You So Much..and the update to call activity with parameters made my day..!!

    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from HTML5 CSS3 Javascript Online Training from India . or learn thru HTML5 CSS3 Javascript Online Training from India. Nowadays JavaScript has tons of job opportunities on various vertical industry. HTML5 CSS3 Javascript Online Training from India

  2. thank Sherif elKhatib! It work perfectly! :)

  3. This is works great.. thank you

  4. Check out for working example using tag

  5. Thanks! This is help for me

  6. I found this as an informative and interesting post,

  7. This comment has been removed by the author.

  8. This comment has been removed by the author.

  9. However nothing of it will be possible if there were not PSD to HTML slicing possibilities. The construction of great buildings, begin with laying down the very basic singular brick in the foundation.
    StartPoint Hastings

  10. It is extremely affordable to invest in an Android based system. Besides, you can get an experienced Android application developer at cost effective rates. Download game killer

  11. Nice information Regarding htmls and links in text view My sincere thanks for sharing this post and please continue to share this kind of post
    Android Training in Chennai

  12. This comment has been removed by the author.

  13. That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.
    Android Online Training

  14. really nice blog has been shared by you.. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
    android training in chennai

  15. Thank you so much for your blog. I have been using it as reference for my students during Android Course in Chennai. It has been so much useful, keep writing more

    Android Training in Chennai

  16. really nice blog has been shared by you. before i read this blog i didn't have any knowledge about this. but now i got some knowledge about this. so keep on sharing such kind of an interesting blogs.
    android training in chennai

  17. Its an amazing article that you share about PSD To HTML conversion. Thank you so much.

  18. Android 3 Apps is other free utility to create an android application for your Android gadgets of your choice.
    Freedom Apk

  19. Based on your requirement, you should hire an experienced Android app developer to create innovative applications for your company.
    Download Game Killer Apk

  20. as it needs to mull over a much lower assortment of gadgets when contrasted with Android. read this

  21. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    Android Training In Gurgaon

  22. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.

  23. In 1876 Thomas Edison invented a machine that ultimately became the tattoo machine, but it took modifications by Samuel O'Reilly in 1891 to adapt the device for tattooing.

    kit tattoo

  24. Keeping in mind, the importance of mobile application and its usability, you can either choose Android or iOS. ShowBox APK

  25. Thank you so much for sharing this amazing article with us.Will stay connected with your blogs for the future posts.
    Summer Courses for Business Administration in Chennai | Best Summer Courses in Porur

  26. I hope these stuffs on Sites To Create Your Own Android Application for Free will help you making your own Android apps and share to your friend and entire world & most important making money through Android Apps.
    Custom Software Development Company

  27. I talked about link value last year but I thought I'd go a few steps further and add to that, covering how Google values links nowadays when link building isn't the center of attention or the entire game that it once was.
    free custom url shortener

  28. The information you have here is really useful to make my knowledge good. It is truly supportive for us and I have accumulated some essential data from this blog.
    Best cloud Computing Training Institute in Chennai | Best cloud Computing Training Institute in Velachery

  29. Nice blog. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    Best Microsoft Azure Training Institute in Chennai | Best Microsoft Azure Training Institute in Velachery

  30. I am really enjoying reading your well-written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    Hadoop course in Marathahalli Bangalore
    DevOps course in Marathahalli Bangalore
    Blockchain course in Marathahalli Bangalore
    Python course in Marathahalli Bangalore
    Power Bi course in Marathahalli Bangalore

  31. I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information. vpn

  32. Just pure brilliance from you here. I have never expected something less than this from you and you have not disappointed me at all. I suppose you will keep the quality work going on.

  33. This book gives you step wise extensive guide along with three golden lessons that helps your kids learn all the right things about survival die besten vpn

  34. Really it was an awesome article… very interesting to read…Thanks for sharing.........


  35. definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog! vpnveteran

  36. Bored of sitting at home? Play casino and get paid for it perfect popular online casinos Play and win.

  37. Make a lot of money with online casino BGAOC we have top rated online casinos If you want to always be in the money, then try to play online casino with us.

  38. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
    Java Training in Chennai
    Java course in Chennai
    Hadoop Training in Chennai
    Python Training in Chennai
    Java Training in Porur
    Java Training in Adyar
    Java Training in Tnagar

  39. In the beginning, I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips. I like your writing style and I hope you will keep doing this good working.
    Hacking Course in Chennai
    Hacking Classes in Chennai
    AWS Training in Chennai
    Data Science Course in Chennai
    Digital Marketing Course in Chennai
    Hacking Training in Tambaram
    Hacking Training in Velachery
    Hacking Training in OMR

  40. Знаю где продается отличная rgb лента, покупал у них недавно, нареканий нет, компания называется Ekodio

  41. Imagine yesterday went to some online casino copacetic best online gambling real money and decided to ponastalgirovat. so many pleasant memories when you again see this slot machine mmm cool