Android connection between two actions in one package

I created an Android application with two actions: LoginActivity and RegisterActivity. I need to switch between them using the "a href" tag. So I did this in my AndroidManifest.xml file.

<activity android:name="com.example.test.RegisterActivity" android:label="@string/app_name" > <intent-filter> <category android:name="android.intent.category.DEFAULT" /> <action android:name="android.intent.action.VIEW" /> <data android:scheme="com.example.test" /> </intent-filter> </activity> 

In LoginActivity, I just added the "a" tag to my line. This will lead me to RegisterActivity:

 TextView register = (TextView) findViewById(R.id.registerLink); register.setText(Html.fromHtml( "If you don't have an account " + "<a href=\"com.example.test://getApplicationContext\">register</a> ")); register.setMovementMethod(LinkMovementMethod.getInstance()); 

So far, this works fine. Then I want to return to my LoginActivity using the link also: So, I did this in the AndroidManifest file:

  <activity android:name="com.example.test.LoginActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="com.example.test" /> </intent-filter> </activity> <activity 

And here is the problem. In RegisterActivity, I have the same "href" value and it will return me to my registration activity again, although I want to return to loginActivity.

 login = (TextView)findViewById(R.id.loginLink); login.setText(Html.fromHtml( "If you already have an account please " + "<a href=\"com.example.test://getApplicationContext\">login</a> ")); login.setMovementMethod(LinkMovementMethod.getInstance()); 

I do not know how to make the difference between these two actions. Maybe id or some parameter will help me, but I don't know which one. Thanks in advance, I hope someone can help me.

+4
source share
1 answer

In the interest of completeness (and, believe me, a chance for some kind of sweet rap), I answered below.

To start an action using the <a href= link, you need to:

  • Make sure the host and schema are defined in manifest.xml
  • Make the right call in linkable HTML

manifest.xml

 <activity android:name=".LoginActivity"> <intent-filter> <data android:host="loginactivity" android:scheme="my-scheme" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity> 

Then in the code:

 login = (TextView)findViewById(R.id.loginLink); login.setText(Html.fromHtml( "If you already have an account please " + "<a href=\"my-scheme://loginactivity\">login</a> ")); login.setMovementMethod(LinkMovementMethod.getInstance()); 

Credit Sheriff al-Khatib: ( http://www.sherif.mobi/2011/09/html-and-activity-links-in-textview.html )

+1
source

Source: https://habr.com/ru/post/1486372/


All Articles