1. Unable to use the network: Permission denied (maybe missing internet Permission)
Add the Allow Network option in Androidmainifest.xml (after </application> end tag >):
<uses-permission android:name= "Android.permission.INTERNET"/>
2. Activity class not found: Android.content.ActivityNotFoundException:Unable to find explicit activity class {XXXX}
Add a statement of activity in the androidmainifest.xml, such as:
<activity android:name= ". xxxactivity" >
</activity>
3. Why can't I find the Startsubactivity method?
Now, use the Startactivityforresult method instead of the old Startsubactivity method.
4. Unable to load view in XML, Report java.lang.NullPointerException exception
Forgot to load the activity's layout file:
Setcontentview (R.layout.main);
5, unparsed aapt error (s)! Check the console for output
But when you can't find an error on your console or you can't read the error, point to Project--------->clean. It'll be fine.
Http://hovertree.com/menu/android/
6. The difference between Requestcode and ResultCode
When using Startactivityforresult () and Onactivityresult (), Requestcode and ResultCode are used respectively, and sometimes it is very easy to confuse 2 of them.
Requestcode and ResultCode confuse the wrong explanation.
Startactivityforresult (Intent Intent, Int requestcode)Intent passed to B, do not explain, do not understand you or play mobile phone, do not want to develop the things requestcode >=0, casually used in Onactivityresult () to distinguish which sub-module callback data, if there is C.java, D even e sub-modules, each district separate different requestcode is good.
setresut (int resultcode, Intent Intent)ResultCode if the B sub-module may have several different results returned, it can be distinguished by this parameter. There is also a special RESULT_OK value, there is no special case to use it, the SDK is explained, uh. Intent continued not to explain, passed back to a of the Onactivityresult ()
onactivityresult (int requestcode, int resultcode, Intent Intent)Here are three not to explain, and the above corresponding to the thing. If Requestcode and ResultCode are not differentiated, any other activity setresult to a onactivityresult () will be treated with no distinction.
7. Unable to download files to SD card
In the manifest file, add: <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
8. Let the control center in the parent container:
Android:layout_gravity= "Center_vertical"
9. Align the controls at both ends:
The following code gives way to the left and right alignment of the two controls on the same line individually:
<relativelayout
Xmlns:android= "Http://schemas.android.com/apk/res/android"
android:background= "@drawable/top"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
><imageview
Android:id= "@+file_browser/imgrefresh"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_marginleft= "10px"
android:src= "@drawable/refresh"
Android:layout_centervertical= "true"
>
</ImageView>
<imageview
Android:id= "@+file_browser/imgcheck"
Android:layout_alignparentright= "true"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_marginright= "10px"
android:src= "@drawable/close"
Android:layout_centervertical= "true"
>
</ImageView>
</RelativeLayout>
10,Android soft keyboard to the control to the top squeeze solution:
The edge of the screen is outside the keyboard area and is used when defining the layout file: android:gravity= "Bottom" will be squeezed to the top!
Workaround:
Write android:windowsoftinputmode= "Adjustpan" in the corresponding activity in the Androidmainfest.xml file of this project
or write down the size of the layout file in the configuration file!
11. Use ScrollView in the layout:
Put the original layout with <scrollview xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Android:scrollbars= "None" ></ScrollView> allows you to scroll through the view.
12. Global Variables Application Context
Create a subclass of your own android.app.Application and then declare this class in manifest, which is what Android does to create a globally available instance that you can use anywhere else Context.getapplicationcontex The T () method gets the instance and gets the state (variable) in it. Here's a look at the demo:
Class MyApp extends Application {
Private String MyState;
Public String getState () {
return mystate;
}
public void SetState (String s) {
MyState = s;
}
}
Class Blah extends Activity {
@Override
public void OnCreate (Bundle b) {
...
MyApp appState = (MyApp) getapplicationcontext ());
String state = Appstate.getstate ();
...
}
}
This effect is the same as using static variables, but it is more in line with the Android architecture. Using this method, you need to configure it in Androidmanifest.xml:
<application android:name= ". MyApp "
android:icon= "@drawable/icon"
Android:label= "@string/app_name" >
13, theAndroid simulator phone to send text messages
Gphone Simulator has a unique number: 15555218135, this is similar to our physical phone SIM card number. To implement dial-up, use your phone? Of course not!
More simple, three steps:
1. Open the terminal
2. Connection: telnet localhost 5554 (5554 is the number shown above when you open the simulator)
3. Command: GSM call 15555218135
look! Does the caller appear on the simulator? Answer/Hang-up is the same as the physical phone.
Texting is as simple as repeating the above 1, 22 steps, the third command change:
SMS Send 15555218135 hello,this is a Message.
14. The ListView cannot trigger the Onitemclicklistener listener
Checks if EditText is used in the row layout file bound by the row and sets EditText's Focusable property to False if any.
Recommendation: http://www.cnblogs.com/roucheng/p/sdka.html
Common mistakes and tips for Android development