Android開發雜記(一)

來源:互聯網
上載者:User

標籤: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代碼  
  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.   
  11.       StringBuilder log=new StringBuilder();  
  12.       String line;  
  13.       while ((line = bufferedReader.readLine()) != null) {  
  14.         log.append(line);  
  15.       }  
  16.       TextView tv = (TextView)findViewById(R.id.textView1);  
  17.       tv.setText(log.toString());  
  18.     } catch (IOException e) {  
  19.     }  
  20.   }  
  21. }  



詳細參考 
http://www.helloandroid.com/tutorials/reading-logs-programatically 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.