1
2
3
4
5
6
7
8
private void restart(Context context) {
    PackageManager packageManager = context.getPackageManager();
    Intent intent = packageManager.getLaunchIntentForPackage(context.getPackageName());
    ComponentName componentName = intent.getComponent();
    Intent mainIntent = Intent.makeRestartActivityTask(componentName);
    context.startActivity(mainIntent);
    Runtime.getRuntime().exit(0);
}
cs

 

참고 : stackoverflow.com/questions/6609414/how-do-i-programmatically-restart-an-android-app

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// HashMap 저장
public void SaveUrlMap(Context context, HashMap<StringString> hashMapData) {
    SharedPreferences mmPref = context.getSharedPreferences("pref", Context.MODE_PRIVATE);
    if (mmPref != null) {
        JSONObject jsonObject = new JSONObject(hashMapData);
        String jsonString = jsonObject.toString();
        SharedPreferences.Editor editor = mmPref.edit();
        editor.remove("hashMapName").commit();
        editor.putString("hashMapName", jsonString);
        editor.commit();
    }
}
 
// HashMap 불러오기
public HashMap<StringString> LoadUrlMap(Context context) {
    HashMap<StringString> outputMap = new HashMap<StringString>();
    SharedPreferences mmPref = context.getSharedPreferences("pref", Context.MODE_PRIVATE);
    try {
        if (mmPref != null) {
            String jsonString = mmPref.getString("hashMapName", (new JSONObject()).toString());
            JSONObject jsonObject = new JSONObject(jsonString);
 
            Iterator<String> keysItr = jsonObject.keys();
            while (keysItr.hasNext()) {
                String key = keysItr.next();
                String value = (String) jsonObject.get(key);
                outputMap.put(key, value);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return outputMap;
}
cs

해당 증상은 기기 내에 backup data가 남아있기 때문이다.

manifest.xml에서

1
2
3
4
5
<application
...
android:allowBackup="false"
...
</application>
cs

추가하면 해결됨.

 

res 폴더 내부에 "font"폴더 생성.

"resource/font/폰트이름.ttf" 파일 넣고

res/values/styles.xml

1
2
3
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:fontFamily">@font/폰트이름</item>
    </style>
 
cs

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    private void showPickerView(){
        final String items[] = {"아이템1","아이템2","아이템3"};
        int mmSelectedNum = 0;
        AlertDialog.Builder mmBuilder = new AlertDialog.Builder(this);
        mmBuilder.setTitle("선택창");
        mmBuilder.setSingleChoiceItems(items, mmSelectedNum, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int selected) {
                switch (selected){
                    case 0:
                        Toast.makeText(this"아이템1", Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        Toast.makeText(this"아이템2", Toast.LENGTH_SHORT).show();
                        break;
                    case 2:
                        Toast.makeText(this"아이템3", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
        AlertDialog mmAlert = mmBuilder.create();
        mmAlert.setCanceledOnTouchOutside(true);
        mmAlert.show();
    }
cs

 

1
2
3
4
5
Build.SERIAL // is deprecated on API 26.
Build.getSerial() // Use this.
 
//need to set 
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
cs

 

키보드를 숨기는 메소드

1
2
3
4
5
6
7
    private static void hideSoftKeyboard(Activity activity) {
        InputMethodManager inputMethodManager =
                (InputMethodManager) activity.getSystemService(
                        Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), 0);
    }
 
cs

 

null exception 방지

1
2
if (This.getCurrentFocus() != null)
            hideSoftKeyboard(This);
cs

 

+ Recent posts