Summary of trivial knowledge points in Android programming (5)

Source: Internet
Author: User

1. No animation is required to start the program.

Java code
  1. Myintent. setflags (intent. flag_activity_no_animation); // 1.5 should be used, so that no animation effect can be obtained.
  2. 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
  1. File wallpaperdirectory = new file ("/sdcard/wallpaper /");
  2. Wallpaperdirectory. mkdirs ();
  3. File outputfile = new file (wallpaperdirectory, filename );
  4. Fileoutputstream Fos = new fileoutputstream (outputfile );

Be sure to add permissions.

XML Code
  1. <Uses-Permission Android: Name = "android. Permission. write_external_storage"/>

 

3. crossline effect in the middle of the text

Java code
  1. Pricetv. settext ("Price: RMB 2.00 ");
  2. Pricetv. getpaint (). setflags (paint. strike_thru_text_flag );

 

4. Use transactions to operate SQLite databases in Android

Java code
  1. Sqlitedatabase DB = ....;
  2. DB. begintransaction (); // start the transaction
  3. Try {
  4. Db.exe csql ("insert into person (name, age) values (?,?) ", New object [] {" James ",
  5. 4 });
  6. Db.exe csql ("Update person set name =? Where personid =? ", New object [] {" Li Si ", 1 });
  7. DB. settransactionsuccessful (); // call this method to submit the current task when it is executed to endtransaction ().
  8. If this method is not called, the transaction will be rolled back.
  9. } Finally {
  10. DB. endtransaction (); // The transaction identifier determines whether to commit or roll back the transaction.
  11. }
  12. DB. Close ();

 

5. Questions about sms smessage

Java code
  1. Public void onreceive (context, intent ){
  2. // Todo auto-generated method stub
  3. Log. D (TAG, "---> onreceive, SMS reach ");
  4. Bundle bundle = intent. getextras ();
  5. If (bundle! = NULL ){
  6. Object [] PDUS = (object []) bundle. Get ("PDUS ");
  7. Smsmessage [] messages = new smsmessage [PDUS. Length];
  8. For (INT I = 0; I <PDUS. length; I ++ ){
  9. Messages = smsmessage. createfrompdu (byte []) PDUS );
  10. }
  11. For (smsmessage: messages ){
  12. From = smsmessage. getdisplayoriginatingaddress ();
  13. Data = smsmessage. getdisplaymessagebody (). Trim ();
  14. Log. D (TAG, from + "" + data );
  15. // Process content
  16. Response (context, data );
  17. }
  18. }
  19. }

 

6. webview in Android supports multi-touch:

Java code
  1. Public class usingmywebview extends activity {
  2. Private webview mwebview;
  3. @ Override
  4. Public void oncreate (bundle savedinstancestate ){
  5. Super. oncreate (savedinstancestate );
  6. Setcontentview (R. layout. Main );
  7. // Get Web View
  8. Mwebview = (webview) findviewbyid (R. Id. mywebview); // This is the ID you gave to the webview in the main. xml
  9. Mwebview. getsettings (). setjavascriptenabled (true );
  10. Mwebview. getsettings (). setsuppzoom zoom (true );
  11. // Zoom control on Web (you don't need this if Rom supports multi-touch
  12. Mwebview. getsettings (). setbuiltinzoomcontrols (true); // enable multitouch if supported by Rom
  13. // Load URL
  14. Mwebview. loadurl ("http://www.firstdroid.com/advertisement.htm ");
  15. }
  16. }

7. Android program automatically starts at startup:

XML Code
  1. <Cycler Android: Name = ". bootbroadcastreceiver">
  2. <Intent-filter>
  3. <Action Android: Name = "android. Intent. Action. boot_completed"/>
  4. </Intent-filter>
  5. </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
  1. Package com. jftt. bootstart;
  2. Import Android. content. broadcastreceiver;
  3. Import Android. content. context;
  4. Import Android. content. intent;
  5. Public class bootbroadcastreceiver extends broadcastreceiver {
  6. Static final string action = "android. Intent. Action. boot_completed ";
  7. @ Override
  8. Public void onreceive (context, intent ){
  9. If (intent. getaction (). Equals (Action )){
  10. Intent sayhellointent = new intent (context, bootstart. Class); // specify the activity page to be enabled
  11. Sayhellointent. addflags (intent. flag_activity_new_task );
  12. Context. startactivity (sayhellointent );
  13. }
  14. }
  15. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.