標籤:des android style class blog code
1、cygwin環境變數設定
可在Cygwin.bat 中設定
set NDK_ROOT=P:/android/android-ndk-r8e
或者在home\Administrator\.bash_profile中設定
NDK_ROOT=/cygdrive/p/android/android-ndk-r8e
export NDK_ROOT
或者在運行程式前設定(綠色方式)
setlocal enabledelayedexpansion
set NDK_ROOT=%cd%\android-ndk-r8e
start %cd%\adt-bundle-windows-x86-20130522\eclipse\eclipse.exe
NDK與eclipse在同一級目錄下。
2、Android 屬性相關
<application android:icon="@drawable/icon"//應用安裝後案頭顯示的表徵圖
android:label="@string/app_name">
<activity android:name=".FormulaStudy" android:theme="@android:style/Theme.NoTitleBar" //無標題
android:screenOrientation="sensorLandscape" //只允許橫屏切換
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> //第一個Activity
</intent-filter>
</activity>
<uses-library android:name="com.noahedu"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="10"/>
<uses-permission android:name="com.noahedu.permission.AWARD_SCORE"/>
</application>
3、Shell多行注釋
: :||:<<\COMMENTS
注釋內容
COMMENTS
4、SourceInsight配置
AStyle格式化工具: 在Command增加AStyle,在Run填寫"~\AStyle.exe" --style=linux -s4 -S -N -L -m0 -M40 --suffix=none --convert-tabs %f,再配置快速鍵
TabSiPlus外掛式的檔案標籤,下載後運行後再執行sourceinsight主程式
3、定時操作
Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable()
{
@Override
public void run()
{
}
}, 3000);
4、TagSoup 是一個Java開發符合SAX的HTML解析器
5、android-ndk-r8e/build/gmsl/__gmsl:512: *** non-numeric second argument to `wordlist‘ function: ‘‘.
將AndroidManifest.xml檔案先移動到其他地方,編譯成功後再mv回來,這樣操作果然成功。
6、
程式主動觸發系統回收資源
System.runFinalization();
System.gc();
進程真正退出
System.exit(0);
1.不需要後台啟動並執行app需在退出時調用上面的代碼,以便系統回收資源和進程真正退出
2.app運行過程中也可以在合適的時候主動觸發系統回收資源
基本上是Activity退到後台時加入以下一段代碼處理
if (isTaskRoot()) {
System.runFinalization();
System.gc();
System.exit(0);
}
7、退出所有Activity的方法
在BaseActivity類中
private static LinkedList<Activity> activityList = new LinkedList<Activity>();
在onCreate中activityList.add(this);每次進入新的Activity將this指標壓入鏈表,
重寫onDestroy()方法移除相應的Activity,activityList.remove(this);
退出所有的Activity時,只要調用finish();方法,並移除所有的Activity就可以了。
8、android系統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
注意函數名稱命名方式。
java|包名|類名稱|函數名稱
Java_com_noahedu_dataparser_ImageDecoder_decode
9、jni調試
//在C工程、android工程 調試切換
#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雜記
jstring path
const char *file = (*env)->GetStringUTFChars(env, path, NULL);
(*env)->ReleaseStringUTFChars(env, path, file);
11、取消代碼混淆編譯
LOCAL_PROGUARD_ENABLED := disabled
12、使用jar包名稱區分大小寫
<uses-library
android:name="PenWriterLib"
android:required="false" />
13、listview背景黑塊問題
android:cacheColorHint="#00000000"
12、在android程式中,如何將LogCat上的日誌輸出到檔案?
LogCat儲存在circular memory buffers中。
(1)、可以通過命令來匯出Log:
引用adb logcat -d > logcat.txt
詳細參考
http://developer.android.com/tools/help/adb.html#logcat
(2)、在程式中擷取Log的方法:
引用<uses-permission android:name="android.permission.READ_LOGS" />
Java代碼
- public class LogTest extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- try {
- Process process = Runtime.getRuntime().exec("logcat -d");
- BufferedReader bufferedReader = new BufferedReader(
- new InputStreamReader(process.getInputStream()));
-
- StringBuilder log=new StringBuilder();
- String line;
- while ((line = bufferedReader.readLine()) != null) {
- log.append(line);
- }
- TextView tv = (TextView)findViewById(R.id.textView1);
- tv.setText(log.toString());
- } catch (IOException e) {
- }
- }
- }
詳細參考
http://www.helloandroid.com/tutorials/reading-logs-programatically