We have already learned about the startup activity. After entering the startup interface, we can open other activity, enter the second and third levels, etc.; next we will learn how to open and close other activity;
Open the application activity
For example, now we need to open the activity corresponding to sub.ftu. According to the previous analysis of the start activity, we can know that the activity object corresponding to the UI resource is subActivity. These are the codes automatically generated by the tool for us. We don't need to pay attention to too many details, just understand it briefly. Then we can start the activity with the following code:
EASYUICONTEXT->openActivity("subActivity");
If we want to jump to the sub.ftu activity through a button click, we can call the above statement in the callback function of the button click event:
static bool onButtonClick_Button1(ZKButton *pButton) {
// Jump to the sub.ftu activity
EASYUICONTEXT->openActivity("subActivity");
return false;
}
Under normal circumstances, the above calling code is sufficient. If some information needs to be passed between the activity and the activity, such as the payment page, we need to use the second parameter of openActivity to pass parameters :
Intent *pIntent = new Intent();
pIntent->putExtra("cmd", "open");
pIntent->putExtra("value", "ok");
EASYUICONTEXT->openActivity("subActivity", pIntent);
In this way, it can be received in the onUI_intent
callback of subLogic.cc :
static void onUI_intent(const Intent *intentPtr) {
if (intentPtr) {
// Key value analysis
std::string cmd = intentPtr->getExtra("cmd"); // "open"
std::string value = intentPtr->getExtra("value"); // "ok"
......
}
}
Note:
1. The new Intent does not need to be manually deleted, it is automatically deleted within the framework.
2. putExtra only provides the key-value pair method of string. If you need to pass int or other types of values, you need to convert to string type, and then do the corresponding conversion after receiving it in onIntent
Close the application activity
Through the openActivity function above, we opened the subActivity. At this time, we want to go back to the original activity. What should we do? We can return to the previous activity through the following code:
EASYUICONTEXT->goBack();
If the return is triggered by a button, we can directly use the tool to set the button ID value to sys_back
, and the system will respond to the return function;
If we enter a more hierarchical activity and want to directly go back to our first startup interface, we can implement it with the following code :
EASYUICONTEXT->goHome();
It returns to the main activity.
In addition, if it is also triggered by a button, we can also use the tool to set the button's ID value to sys_home
, and the system will also respond to the function of returning to the main activity;
Finally, we can also close the activity through the closeActivity function of EasyUIContext, for example, we want to close the subActivity :
EASYUICONTEXT->closeActivity("subActivity");
This function requires the caller to know the name of the activity to be closed; in addition, this method cannot close the startup activity, which is always present.