Reputation: 291
I wanna to redirect to the Android Activity from java class..
here my code
class A {
getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")));
}
from the code,it's redirected to webview instead i need it to redirect it into Android Activity something like this..
getContext().startActivity(
new Intent(A.this,My.class));
Upvotes: 1
Views: 3153
Reputation: 1442
Maybe Extra will fit your need:
Intent myIntent = new Intent(this,myActivity.class);
myIntent.putExtra("URL","www.google.de");
startActivity(myIntent);
In myActivity you would do:
String url = getIntent().getExtras().getString("URL");
Cheers.
Upvotes: 0
Reputation: 64409
IF you want to start an activity, and send and url to it, you can do something like this:
Intent myIntent = new Intent(this, YourActivityName.class);
Bundle sendInfo = new Bundle();
sendInfo.putString("YOUR.IDENTIFIER.YOURURL","http://www.google.com");
myIntent.putExtras(sendInfo);
this.startActivity(myIntent);
Now if you want to do this from outside, like your activity catching url intents, you should add an intent-filter to your manifest, so you can handle those (after you get the "which program do you want to use to open this dialog). That would look something like this:.
<activity android:name=".YourActivityName">
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme ="http"
android:host ="www.hosttofilter.tld"
android:pathPrefix="/view">
</data>
</intent-filter>
This wil open all url requests for "http://www.hosttofilter.tld" with your app
Upvotes: 1
Reputation: 35598
To address your question about how to start a specific Activity
check out this article. It provides several examples of exactly what you want to do. The second question is where are you calling this code? Is it from an Activity class or is it from some plain old java object? Hint: the code you posted won't work from a POJO.
Upvotes: 0