Intent And Start Activity From String
I have a little problem. I want to start activity but in something other way. I know that Intent i = new Intent(this, ActivityTwo.class); initialize intent and after that I can
Solution 1:
Try this:
startActivity(this, Class.forName(yourStringClass));
Solution 2:
Here is a code by which you can start activity using the name of the activity
Class<?> c = null;
if(StringClassname != null) {
try {
c = Class.forName(StringClassname );
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Intent intent = new Intent(mail.this, c);
startActivity(intent);
Here class name will be full name of the class with the package name. For example if your package name will be x.y.z and if you have Activity name called A then the full name of the Activity A will be x.y.z.A.
Solution 3:
You can look up a Class
by name using Class.forName("MyString")
Solution 4:
Just use....
Intentintent=newIntent().setClassName(activity,"packageName"+"className");
startActivity(intent);
Solution 5:
Class<?> c =Class.forName("YOUR STRING" );
Intentintent=newIntent(FirstActivity.this, c);
startActivity(intent);
Post a Comment for "Intent And Start Activity From String"