Android Development Notes (i)

Source: Internet
Author: User

1. Cygwin environment variable setting

Can be set in Cygwin.bat

Set ndk_root=p:/android/android-ndk-r8e

or set in Home\administrator\.bash_profile

ndk_root=/cygdrive/p/android/android-ndk-r8e
Export Ndk_root

or set before running the program (green mode)

Setlocal enabledelayedexpansion
Set ndk_root=%cd%\android-ndk-r8e
Start%cd%\adt-bundle-windows-x86-20130522\eclipse\eclipse.exe

The NDK and eclipse are in the same level directory.

2, Android Properties related

<application android:icon= "@drawable/icon"//icon for desktop display after application installation

Android:label= "@string/app_name" >

<activity android:name= ". Formulastudy "Android:theme=" @android: Style/theme.notitlebar "//Untitled
android:screenorientation= "Sensorlandscape"//allow only horizontal screen switching
Android:label= "@string/app_name" >

<intent-filter>

<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>//First activity
</intent-filter>
</activity>
<uses-library android:name= "com.noahedu"/>

<USES-SDK android:minsdkversion= "4" android:targetsdkversion= "Ten"/>
<uses-permission android:name= "Com.noahedu.permission.AWARD_SCORE"/>

</application>

3, Shell multi-line Comment

:: | |:<<\comments

Comment Content

COMMENTS

4. Sourceinsight Configuration

Astyle formatting tool: Add Astyle in command, fill "~\astyle.exe"--style=linux-s4-s-n-l-m0-m40--suffix=none--convert-tabs%f in run, and match Reset shortcut keys

Tabsiplus plug-in file label, after downloading and then run the Sourceinsight main program

3. Timed operation

Handler Mhandler = new Handler ();

Mhandler.postdelayed (New Runnable ()
{
@Override
public void Run ()
{
}
}, 3000);

4,Tagsoup is a Java development of SAX-compliant HTML parser

5, android-ndk-r8e/build/gmsl/__gmsl:512: * * * non-numeric second argument to ' wordlist ' function: '.

Move the Androidmanifest.xml file to a different place first, and then MV back after the successful compilation, so the operation is successful.

6.

The program actively triggers the system to recycle resources
System.runfinalization ();
System.GC ();
Process really quits
System.exit (0);

1. Apps that do not need to run in the background should invoke the above code on exit so that the system reclaims the resources and the process really exits
2.app can also actively trigger the system to recycle resources at the right time during the operation.

Basically, when the activity is back in the background, add the following code processing
if (Istaskroot ()) {
System.runfinalization ();
System.GC ();
System.exit (0);
}

7. How to exit all activity

In the Baseactivity class

private static linkedlist<activity> activitylist = new linkedlist<activity> ();

Activitylist.add (this) in OnCreate, and each time it enters a new activity, it presses the this pointer into the linked list,

Override the OnDestroy () method to remove the corresponding activity,activitylist.remove (this);

When you exit all activity, just call the finish () method and remove all activity.

8. Example of an Android system JNI

public class Imagedecoder {
static{
System.loadlibrary ("Mathappliedprodec");
}
Public native Boolean decode (String path, Bitmap Bitmap, int imageType);
Public native Boolean encode (String path, Bitmap Bitmap, int imageType);
}

#include <jni.h>

#ifndef _included_com_noahedu_dataparser_imagedecoder
#define _included_com_noahedu_dataparser_imagedecoder
#ifdef __cplusplus
extern "C" {
#endif

Jniexport Jboolean Jnicall Java_com_noahedu_dataparser_imagedecoder_decode
(JNIEnv *, Jobject, jstring, Jobject, Jint);
Jniexport Jboolean Jnicall Java_com_noahedu_dataparser_imagedecoder_encode
(JNIEnv *, Jobject, jstring, Jobject, Jint);


#ifdef __cplusplus
}
#endif
#endif

Notice how the function names are named.

Java| Package name | class name | function name

Java_com_noahedu_dataparser_imagedecoder_decode

9. JNI Debugging

In C Engineering, Android Engineering debug switch
#ifdef ANDROID
#include <android/log.h>
#define LOG_TAG "Mathapplied"
#define Logi (...) __android_log_print (Android_log_info, Log_tag, __va_args__)
#else
#define Logi (...) printf (__va_args__);
#endif

10. JNI Essays

Jstring Path

const char *file = (*env)->getstringutfchars (env, Path, NULL);

(*env)->releasestringutfchars (env, path, file);

11. Cancel code Obfuscation compilation

local_proguard_enabled: = disabled

12. Case sensitivity using JAR package name

<uses-library
Android:name= "Penwriterlib"
Android:required= "false"/>

13, the ListView background black block problem

Android:cachecolorhint= "#00000000"

12, in the Android program, how to output the log on the logcat to a file?

The logcat is stored in the circular memory buffers.

(1), you can export log by command:

cite adb logcat-d > Logcat.txt



Detailed reference
Http://developer.android.com/tools/help/adb.html#logcat

(2), the method of obtaining log in the program:

Reference <uses-permission android:name= "Android.permission.READ_LOGS"/>



Java code
  1. Public class Logtest extends Activity {
  2. @Override
  3. public void OnCreate (Bundle savedinstancestate) {
  4. super.oncreate (savedinstancestate);
  5. Setcontentview (R.layout.main);
  6. try {
  7. Process process = Runtime.getruntime (). EXEC ("logcat-d");
  8. BufferedReader BufferedReader = new BufferedReader (
  9. New InputStreamReader (Process.getinputstream ()));
  10. StringBuilder log=New StringBuilder ();
  11. String Line;
  12. While (line = Bufferedreader.readline ()) = null) {
  13. Log.append (line);
  14. }
  15. TextView TV = (TextView) Findviewbyid (R.ID.TEXTVIEW1);
  16. Tv.settext (Log.tostring ());
  17. } catch (IOException e) {
  18. }
  19. }
  20. }



Detailed reference
Http://www.helloandroid.com/tutorials/reading-logs-programatically

Related Article

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.