how to use variable while calling new activity in intent?

后端 未结 7 1533
失恋的感觉
失恋的感觉 2021-01-22 01:08

i have following code to call new activity

now i want to use variable to call new activity

String var1,var2,var3; var1=\"Login\"; var2=\"Signup\"; var3=\"more

7条回答
  •  抹茶落季
    2021-01-22 01:54

    From the link Maurits gave, you can also have a look at the putExtras methods.

    See more info here and search for putExtra (the URL doesnt look good on SO)

    *Edited:

    From Donal Rafferty post, I think I understand now what you mean in the OP.

    What you can do is the below:

    String theClass = "Login";
    StringBuilder myAction = new StringBuilder("com.yourpackage.");
    myAction.append(theClass);
    Intent i = new Intent(myAction.toString());
    startActivity(i)
    

    The myAction string (in this example com.yourpackage.Login should be specified in the AndroidManifest.xml under an activity

    From the doc:

    public Intent (String action)

    Since: API Level 1 Create an intent with a given action. All other fields (data, type, class) are null. Note that the action must be in a namespace because Intents are used globally in the system -- for example the system VIEW action is android.intent.action.VIEW; an application's custom action would be something like com.google.app.myapp.CUSTOM_ACTION.

提交回复
热议问题