There are a few minor problems with the development of a compatible tablet app in Android studio using fragment. Since the development was designed to be compatible with mobile phones and tablets, A and B two simulators were used, one for test phones and one for test tablets. There was no problem with emulator a running the app, and Emulator B ran the app but showed an exception.
Simulator a works as follows:
The emulator B app effect runs as follows, with the same fragment on the left title page and the home page, when the app runs without the data being loaded.
It is suspected that when the app starts, some methods do not execute properly, causing some application data to not load. Because the initialization operation is done in Onattach (). Looking at the code, the editor prompts you to find that Onattach () in fragment has two methods to overwrite (activity activity), one is Onattach (context context), and the former is obsolete. I am using the Onattach (context context). Add the output information to the code.
Public void Onattach (Context context) { superOnattach (context); Initnews (); New Newsadapter (context,r.layout.news_item,newslist); " Onattach ");}
The comparison found that when emulator a runs the application, Onattach (context context) is executed normally, and this method is not executed once it is deployed to emulator B. After replacing the Onattach (context context) with Onattach (activity activity), the deployment to emulator A, Onattach () executes normally and the problem is resolved.
Questions about the Onattach () method in fragment sometimes fail to load properly