1. No animation is required to start the program.
Java code
- Myintent. setflags (intent. flag_activity_no_animation); // 1.5 should be used, so that no animation effect can be obtained.
- Getwindow (). setwindowanimations (1) // 1.6 should be used. Do not forget to put it in Activity
2. Create a directory for the SD card
Java code
- File wallpaperdirectory = new file ("/sdcard/wallpaper /");
- Wallpaperdirectory. mkdirs ();
- File outputfile = new file (wallpaperdirectory, filename );
- Fileoutputstream Fos = new fileoutputstream (outputfile );
Be sure to add permissions.
XML Code
- <Uses-Permission Android: Name = "android. Permission. write_external_storage"/>
3. crossline effect in the middle of the text
Java code
- Pricetv. settext ("Price: RMB 2.00 ");
- Pricetv. getpaint (). setflags (paint. strike_thru_text_flag );
4. Use transactions to operate SQLite databases in Android
Java code
- Sqlitedatabase DB = ....;
- DB. begintransaction (); // start the transaction
- Try {
- Db.exe csql ("insert into person (name, age) values (?,?) ", New object [] {" James ",
- 4 });
- Db.exe csql ("Update person set name =? Where personid =? ", New object [] {" Li Si ", 1 });
- DB. settransactionsuccessful (); // call this method to submit the current task when it is executed to endtransaction ().
- If this method is not called, the transaction will be rolled back.
- } Finally {
- DB. endtransaction (); // The transaction identifier determines whether to commit or roll back the transaction.
- }
- DB. Close ();
5. Questions about sms smessage
Java code
- Public void onreceive (context, intent ){
- // Todo auto-generated method stub
- Log. D (TAG, "---> onreceive, SMS reach ");
- Bundle bundle = intent. getextras ();
- If (bundle! = NULL ){
- Object [] PDUS = (object []) bundle. Get ("PDUS ");
- Smsmessage [] messages = new smsmessage [PDUS. Length];
- For (INT I = 0; I <PDUS. length; I ++ ){
- Messages = smsmessage. createfrompdu (byte []) PDUS );
- }
- For (smsmessage: messages ){
- From = smsmessage. getdisplayoriginatingaddress ();
- Data = smsmessage. getdisplaymessagebody (). Trim ();
- Log. D (TAG, from + "" + data );
- // Process content
- Response (context, data );
- }
- }
- }
6. webview in Android supports multi-touch:
Java code
- Public class usingmywebview extends activity {
- Private webview mwebview;
- @ Override
- Public void oncreate (bundle savedinstancestate ){
- Super. oncreate (savedinstancestate );
- Setcontentview (R. layout. Main );
- // Get Web View
- Mwebview = (webview) findviewbyid (R. Id. mywebview); // This is the ID you gave to the webview in the main. xml
- Mwebview. getsettings (). setjavascriptenabled (true );
- Mwebview. getsettings (). setsuppzoom zoom (true );
- // Zoom control on Web (you don't need this if Rom supports multi-touch
- Mwebview. getsettings (). setbuiltinzoomcontrols (true); // enable multitouch if supported by Rom
- // Load URL
- Mwebview. loadurl ("http://www.firstdroid.com/advertisement.htm ");
- }
- }
7. Android program automatically starts at startup:
XML Code
- <Cycler Android: Name = ". bootbroadcastreceiver">
- <Intent-filter>
- <Action Android: Name = "android. Intent. Action. boot_completed"/>
- </Intent-filter>
- </Cycler>
Add the receiver tag to the application tag of the manifest file, and Android: Name specifies a broadcastreceiver. filter the broadcast that is completed when the device is started.
Java code
- Package com. jftt. bootstart;
- Import Android. content. broadcastreceiver;
- Import Android. content. context;
- Import Android. content. intent;
- Public class bootbroadcastreceiver extends broadcastreceiver {
- Static final string action = "android. Intent. Action. boot_completed ";
- @ Override
- Public void onreceive (context, intent ){
- If (intent. getaction (). Equals (Action )){
- Intent sayhellointent = new intent (context, bootstart. Class); // specify the activity page to be enabled
- Sayhellointent. addflags (intent. flag_activity_new_task );
- Context. startactivity (sayhellointent );
- }
- }
- }