is it possible to generate an on click event of another activity with an intent of other class
public void onClick(View v) {
//what ever it is in classA
}
with this type in another class
Intent i = new Intent(context, ClassA.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
or just assume like that generate an event when we go to another class through intent
Given that you want to run some code from onClick()
public void onClick(View v) {
someMethod();
}
you can always trigger it with a parameter sent via the Intent
Intent i = new Intent(context, ClassA.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("some_flag", true);
context.startActivity(i);
and then in ClassA
's onCreate()
if (getIntent().getBooleanExtra("some_flag")) {
someMethod();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.