2013-02-08 1 views
0

MainActivity, onlyFirstRunActivity 및 alwaysRunActivity가있는 앱을 구현 중입니다. > onlyFirstRunActivity - -> alwaysRunActivity 앱 실행 후 처음으로 활동 실행 안드로이드 설치

설치 한 후 또는 그 갱신에 내 응용 프로그램주기가해야

MainActivity : 지금은 내 응용 프로그램주기가 그렇게해야 응용 프로그램의 그 응용 프로그램 installtion 또는 그 갱신에서 원하는 :

MainActivity -> alwaysRunActivity

나는이 상황을 구현할 수있는 방법

+2

SharedPreferences는 첫 번째 실행인지 여부를 알려주는 'bFirstRun' 부울을 저장할 수 있습니다. –

+0

하지만 마지막으로 저장된 sharedprefences는 updation.Means에 남아 있습니다. 어떻게 업데이트를 업데이트 할 수 있습니까? – User42590

+1

무슨 뜻인지 잘 모르겠지만'bFirstRun'이라는 SharedPreference가 없다면 처음 실행했을 것입니다. 그런 다음 false로 설정하고 변경을 커밋합니다. 다음 번에 거기에, 틀렸어. 그래서 고토'alwaysRunActivity' –

답변

1

앱의 업데이트 시간을 가져 와서 SharedPreference에 저장할 수 있습니다.

또한 주 활동을 항상 실행시켜야합니다.

//In your onCreate for your main activity/. 
if(last_update_preference < current_update_time){ 
    Update last update preference to current update time. 
    Run first activity. (Which will finish and bounce you back); 
} 

가 current_update_time 얻으려면 :

How to get app install time from android

마지막 업데이트 시간의 경우를 참조하십시오

http://developer.android.com/guide/topics/data/data-storage.html#pref

+0

나는 updation을 위해서만 작동 할 것이라고 나는 생각한다. 처음 설치하면 어떨까요 ?? 그리고 sharedprefence는 안전한 방법입니까 ?? – User42590

+0

SharedPreference의 기본값으로 0을 반환하면 처음 설치시 작동하고 마지막으로 수정 한 시간은 설치 시간이어야합니다. (연결된 스택 오버 플로우 질문에 표시됩니다.) – Edison

+0

처음으로 last_update_preference의 값은 무엇입니까 ?? – User42590

0

당신은 이런 식으로 뭔가를 시도 할 수 있습니다 :

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    App app = (App)getApplication(); 
    if (app.getApi() != null){ 
     super.onBackPressed(); 
     startActivity(new Intent(this, MainActivity.class)); 
     return; 
    }else showLoginForm();//or do something else. 
} 
,536,
+0

나는 왜 당신이 app.getAp를 얻는 지 이해하지 못했다 ?? 그리고 로그인 폼은 무엇입니까 ?? – User42590

+0

getApi() 메소드는 공유 환경 설정에서 생성하는 api 클래스의 객체를 반환합니다. 따라서 시작이 처음이 아님을 의미합니다. 그리고 나는 새로운 활동을 시작합니다. 아니면 api = null ots는 시작이 먼저라는 것을 의미하고 로그인 양식을 보여줍니다. – Vetalll

0

이렇게 새 설치와 업데이트가 달라질 수 있습니다.

String StoredVersionname = ""; 
    String VersionName; 
    AlertDialog LoginDialog; 
    AlertDialog UpdateDialog; 
    AlertDialog FirstRunDialog; 
    SharedPreferences prefs; 

    public static String getVersionName(Context context, Class cls) { 
       try { 
        ComponentName comp = new ComponentName(context, cls); 
        PackageInfo pinfo = context.getPackageManager().getPackageInfo(
          comp.getPackageName(), 0); 
        return "Version: " + pinfo.versionName; 
       } catch (android.content.pm.PackageManager.NameNotFoundException e) { 
        return null; 
       } 
      } 

    public void CheckFirstRun() { 
       VersionName = MyActivity.getVersionName(this, MyActivity.class); 
prefs = PreferenceManager.getDefaultSharedPreferences(this); 
       StoredVersionname = (prefs.getString("versionname", null)); 
       if (StoredVersionname == null || StoredVersionname.length() == 0){ 
        FirstRunDialog = new FirstRunDialog(this); 
        FirstRunDialog.show(); 
       }else if (StoredVersionname != VersionName) { 
        UpdateDialog = new UpdateDialog(this); 
        UpdateDialog.show(); 
       } 
       prefs.edit().putString("versionname", VersionName).commit(); 
      }