我的应用程序中有很多操作键,例如,我将活动A的意图发送到活动B,我有这个操作键“com.mysite.COUNT”。它属于它在活动A或B中,当你有很多不属于一个类的常量时,你是否制作一个单独的文件并将其命名为常量(某事)?
答案 0 :(得分: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);