2012-01-31 53 views
0

我在我的應用程序中有很多操作鍵,例如,即時消息從活動A發送意圖到活動B,我有這個操作鍵「com.mysite.COUNT」。它屬於它在活動A或B中,當你有很多不屬於一個類的常量時,你是否創建了一個單獨的文件並將其命名爲常量(某事)?應在Android中添加哪些活動(類)常量操作鍵?

回答

0

我個人去使用這種方法:

public static class S { 

    public static class intent { 
     public static final int intent1 = 1; //register request 
     public static final int intent2 = 2; //take a picture request 
    } 

    public static class result { 
     public static final int result1 = 1; //user canceled 
     public static final int result2 = 2; //user signed in successfully 
    } 

    public static class extra { 
     public static final int extra1 = 1; //chosen image 
     public static final int extra2 = 2; //whatever 
    } 
} 

我得到我的常量,就像我讓我的佈局和資源:

Intent intent = new Intent(Activity1.this, Activity2.class); 
startActivityForResult(intent, S.intent.intent1); 
+0

有意思,你怎麼命名您的類,它包含了所有的他們通常(例如S)? – Jimmy 2012-01-31 22:57:06

+0

我保持S(對我來說它代表靜態)。我喜歡保持它S,它看起來像R.id.someid/R.layout.somelayout ... S.prefs.push/S.extra.username ... – 2012-01-31 23:05:25

+0

哦,我希望我明白你的意思在你的題 (: – 2012-01-31 23:06:09