내 응용 프로그램에는 응용 프로그램의 여러 활동 사이를 전환하는 데 사용하는 몇 가지 "의도"가 있습니다. 삼성 기기에서 발생하는 이상한 행동을 알았지 만 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>
는 이미 는 발사 모드를 제거 할뿐만 아니라 singleTop
및 standard
에 응용 프로그램 실행 모드를 변경을 시도했다.
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**)
}
어떤 도움 주셔서 감사합니다!
응용 프로그램에만 singleInstance를 추가하려고 했습니까? – MiltoxBeyond
왜 SingleInstance 실행 모드가 필요합니까? – Shaishav
다른 옵션은 더 새로운 조각 생명주기로 이동하는 것입니다. 프래그먼트는 하나의 액티비티로 대체되고 모두 추가 될 수 있습니다. – MiltoxBeyond