Baidu Maps made a retrieval mistake and could not get the result. He thought it was caused by asynchronous tasks, but there were still some places that could not be explained.

  android, question

This is the previous code
private String city;
private String choice;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
 SDKInitializer.initialize(getApplicationContext());
 setContentView(R.layout.activity_main);
 mPoiSearch = PoiSearch.newInstance();
 String city = "wuhan";
 String keyword = "restaurant";
 PoiCitySearchOption arg0 = new PoiCitySearchOption().city(city)
 .keyword(choice).pageCapacity(10);
 mPoiSearch.searchInCity(arg0);
 
 mPoiSearch.setOnGetPoiSearchResultListener(new
 OnGetPoiSearchResultListener(){
 @Override
 public void onGetPoiResult(PoiResult arg0) {
 List<PoiInfo> list = arg0.getAllPoi();
 bracket
 
 @Override
 public void onGetPoiDetailResult(PoiDetailResult arg0)
 bracket
 bracket
 });

This writing will directly report an error, and the list obtained in the onGetPoiResult callback method will always be null.
But if you put mPoiSearch.searchInCity(arg0); This sentence can be put into the click event of the button and executed to get the data. I decompiled Baidu Maps’s file and looked at the source code. I didn’t see what the problem was. I feel that even if the data has not been obtained due to the asynchronous task, what is the use of the monitoring set by setongetpoisearchhresultener? is the original intention of this monitoring not to trigger the onGetPoiResult method after the data is returned, so I think it doesn’t make sense to guess the asynchronous task. So I really want to know what was done between the launch of the application and the click of the button. There are two steps to initiate the search: to encapsulate a PoiCitySearchOption object and initiate the search; What’s wrong with this, alas, the first large sum

“if we put mPoiSearch.searchInCity(arg0); This sentence can be put into the click event of the button and executed to get the data. “
There is a normal callback
It doesn’t work if you put it outside. It seems that its initialization is asynchronous and takes some time, so even if you have mPoiSearch.searchInCity(arg0); Nor has it really been implemented