0

I have a TextView that is Hyperlinked. The code like this

textPaymentMethod.setText(
Html.fromHtml("<b><a href=\"shippinginfo-activity://shippinginfo\">Add Payment Method</a></b>"));
tvPaymentMethod.setMovementMethod(LinkMovementMethod.getInstance());

When a user Click on AddPayment method it will go Another Activity like ActivityX. But my problem is, I want to pass some data from current Activityto ActivityX. Any suggestions will be appreciated.

jimpanzer
  • 3,470
  • 4
  • 44
  • 84
androidcodehunter
  • 21,567
  • 19
  • 47
  • 70

4 Answers4

1

Have you seen the answer to this Question. Look in the comments which detail a method for passing data to another activity through the use of strings.

Community
  • 1
  • 1
Phil Applegate
  • 567
  • 2
  • 9
  • Although it would have been good to popular this with the answer instead of the link to the answer. This link did help me though so +1 – Simon Jan 16 '16 at 19:08
0

In order to move from one activity to other write the following code

//move to next activity
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
//pass your data here
intent.putExtra("data", <your data value>);
//start Activity
startIntent(intent);
In Activity3, to get your edit text value do the following.

//get your data value here which is passed in FirstActivity
String data = getIntent().getStringExtra("data");

The variable "data" is the final output which you are looking for.

Kameswari
  • 738
  • 7
  • 27
0

Add this in your current Activity

Intent activity= new Intent(Activity.this, ActivityX.class);

activity.putExtra("key", <value>);

startIntent(activity);

ActivityX: in OnCreate()

Intent value = getIntent();
String str_value= (String) usrid.getSerializableExtra("key");
Android
  • 106
  • 5
0

So I figured it out with Phil's help and I read this answer here: handle textview link click in my android app

Add the following intent-filter to the manifest activity you want to hyperlink to, of course replacing the scheme with your own scheme:

<intent-filter>
    <category android:name="android.intent.category.DEFAULT" />
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="com.package.name" />  
</intent-filter>

Now, create your hyperlink with the scheme and put it within your string file. My link has the same android:scheme as the intent-filter and it is appended by an actual external link to a site on the internet. In my case, I want to click on the link, it must open another activity and the other activity has a webview which would display the webpage. This prevents the user from seeing the url of the webpage I have directed them to on the phone.

<string name="signing_in">&lt;a href=&quot;com.package.name://http://your_real_external_link_goes_here&quot;&gt;Privacy Policy&lt;/a&gt;</string>

In my activity with the webview, I say:

    Uri data = getIntent().getData();
    if (data != null) {
        url = data.toString().substring(19 , data.toString().length());
        Log.e("url", url);
    }

We substring out the part that says: com.package.name:// which in total is 19 character and you the remaining portion would be my url which I can then use to load my webpage without the url being displayed.

Community
  • 1
  • 1
Simon
  • 19,658
  • 27
  • 149
  • 217