2016-07-26 1 views
1

내 응용 프로그램에는 응용 프로그램의 여러 활동 사이를 전환하는 데 사용하는 몇 가지 "의도"가 있습니다. 삼성 기기에서 발생하는 이상한 행동을 알았지 만 Nexus 기기에서는 발생하지 않습니다. 새로운 의도가 생성 될 때마다 애플리케이션이이 새로운 활동을위한 두 번째 '작업'을 실행합니다. 사용자가 멀티 태스킹 메뉴로 이동하면 응용 프로그램의 여러 복사본을 볼 수 있습니다! 이것은 바람직한 행동이 아닙니다. 모든 조언이 크게 감사하겠습니다!모든 인 텐트는 Android App에서 새 작업을 시작합니다.이를 방지하려면 어떻게해야합니까?

매니페스트 :

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme" 
    android:launchMode="singleInstance"> 
    <activity 
     android:name=".MainActivity" 
     android:screenOrientation="portrait" 
     android:launchMode="singleInstance"> 
    </activity> 
    <activity 
     android:name=".Settings_area" 
     android:screenOrientation="portrait" /> 
    <meta-data 
     android:name="com.google.android.geo.API_KEY" 
     android:value="AIzaSyDieXTCaFoIL0kJ_IM4UMBSQL3sNn92AWM" /> 

    <activity 
     android:name=".MapsActivity" 
     android:label="@string/title_activity_maps" /> 
    <activity android:name=".Splash" 
     android:launchMode="singleInstance"> 


     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

    </activity> 
    <activity android:name=".aboutPageActivity" /> 
    <activity android:name=".turnOffFromNotification" 
     android:noHistory="true"></activity> 
</application> 

는 이미 는 발사 모드를 제거 할뿐만 아니라 singleTopstandard에 응용 프로그램 실행 모드를 변경을 시도했다.

if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 

       new Handler().postDelayed(new Runnable(){ 
        @Override 
        public void run() { 
      /* Create an Intent that will start the Menu-Activity. */ 
         Intent mainIntent = new Intent(Splash.this,MainActivity.class); 
         Splash.this.startActivity(mainIntent); 
         Splash.this.finish(); 
        } 
       }, splashDisplayLength); 
       return; 
      } 

의도 번째 인스턴스를 작성하십시오 번째 인스턴스를 생성

의도 인스턴스 또한가 발사로부터 생성 될 수

public void goToAboutPage() 
{ 
    Intent goToAboutPage = new Intent(this, aboutPageActivity.class); //create the intent to go to the map screen 
    startActivity(goToAboutPage); //actually go to the map screen 
} 

설정 의도 :

public void changeToSettingsScreen() //changes the screen to the setting screen 
{ 
    readyToSendPackets = false; 
    sendSwitch.setChecked(false); 
    // textView.setText("NOT sending"); //set the textview to advise users packets are not being sent 
    Intent goToSettings = new Intent(this, Settings_area.class); 
    startActivity(goToSettings); 
} 

은 또한을 통해 onNewIntent 방법을 타고 :

protected void onNewIntent(Intent intent) { 
    // super.onNewIntent(intent); //REMOVED THIS TO AVOID DOUBLE INSTANTIATION ON TOUCHWIZ IF ANYTHING BREAKS LOOK HERE FIRST 
    setIntent(intent); //this allows us to recieve the extras bundled with the intent 
    // System.out.println("Here is the bindle: " + getIntent().getExtras()); 
    if (getIntent().getExtras() != null) //check to see if there are any extras, there wont be on apps first start 
    { 
     Bundle extras = getIntent().getExtras(); //get the extras 
     String methodName = extras.getString("methodName"); //assign the extras to local variables 

     if(methodName != null && methodName.equals("turn_send_switch_off")) 
     { 
      sendSwitch.setChecked(false); 
     } 
     //else if(**other actions that may need to be performed can go here**) 
    } 

어떤 도움 주셔서 감사합니다!

+0

응용 프로그램에만 singleInstance를 추가하려고 했습니까? – MiltoxBeyond

+0

왜 SingleInstance 실행 모드가 필요합니까? – Shaishav

+0

다른 옵션은 더 새로운 조각 생명주기로 이동하는 것입니다. 프래그먼트는 하나의 액티비티로 대체되고 모두 추가 될 수 있습니다. – MiltoxBeyond

답변

1

일반적으로 응용 프로그램의 인스턴스 하나를 강제 실행해야하는 경우 각 활동에 인스턴스를 시작하려고 시도 할 때 보려는 각 활동에 android:launchMode="singleInstance"을 넣지 않아야합니다.

launchMode을 응용 프로그램을 제외한 모든 응용 프로그램에서 제거하면 @Shaishav가 말한 것이 사실이지만 응용 프로그램의 단일 인스턴스에서만 실행되도록해야합니다. 대부분의 경우 안드로이드가 응용 프로그램의 수명주기를 설정하지 않도록 할 수 있습니다 한 번에 하나의 인스턴스 만 실행되도록해야 할 필요가 없다면 launchMode을 사용해야합니다.

+0

'android : launchMode'는 '' 태그의 유효한 속성이 아닙니다. 그것은 무시되고 쓸모 없으며 코드를 유지 관리해야하는 사람을 혼동시킬 수 있습니다. 그것을 제거하십시오. –

+0

이것이 대답입니까? 정말? –

관련 문제