2017-07-18 116 views
0

我是新來的機器人,並會很感激任何幫助如何自動防止「重新啓動」活動?

我在我的應用程序有幾個活動。從啓動畫面我啓動我的主要活動(ChooseActivity)。在ChooseActivity我有2個按鈕來啓動2個不同的活動(A和B)。問題出在我處於活動A或B時,應用程序會「/重新啓動」/或在隨機(幾秒鐘時間,幾分鐘時間時間)隨機提供活動選擇活動。我想要防止這種情況,我只想在ChooseActivity時返回(例如,按屏幕上的按鈕)

活動A或B顯示一些彈出窗口,我可以從屏幕上的按鈕關閉o按下手機的後退按鈕,但Activites A或B不能關閉按下手機的返回鍵(我關閉該選項)

我試過在不同的線程所提出的方案,但是沒有結果

這是我的清單:

<activity 
    android:name=".SplashScreen" 
    android:launchMode="singleInstance" 
    android:screenOrientation="portrait"> 
    <intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 
<activity 
    android:name=".A" 
    android:launchMode="singleInstance" 
    android:screenOrientation="portrait"> 
</activity> 
<activity 
    android:name=".B" 
    android:launchMode="singleInstance" 
    android:screenOrientation="portrait"> 
</activity> 

開始選擇電子教案從閃屏:

public void closeSplash() 
{ 
    Intent i = new Intent(); 
    i.setClass(getApplicationContext(), ChooseActivity.class); 
    startActivity(i); 
    finish(); 
} 

打開從ChooseActivity一個活動:

private void goA() 
{ 
    Intent i = new Intent(); 
    i.setClass(getApplicationContext(), A.class); 
    startActivity(i); 
    finish();  
} 

A.java:

... 
@Override 
public void onBackPressed() 
{ 
} 
... 

我將不勝感激任何幫助或指示

謝謝

+0

你必須把意圖在按鈕中的onCreate點擊不那麼當按鈕點擊它重定向 –

+0

份額活性的所有代碼.... – Omi

+0

感謝這麼快回復。我認爲@Pritesh Vadhiya指出了正確的方向。在我的Splash屏幕的「onCreate()」中,在一些動畫和一些延遲之後,我調用方法「closeSplash()」(觸摸屏幕的任何部分也被稱爲相同的方法,並且我沒有等到最後動畫,我直接觸摸屏幕)。從「onCreate()」中刪除此調用似乎可行。我必須做更多的測試,因爲正如我所說,有時它是在幾秒鐘內產生的,有時在幾分鐘內產生。我會在測試後發佈結果。謝謝 – Hern

回答

0

不完成ChooseActivity果阿()方法

private void goA() 
{ 
Intent i = new Intent(); 
i.setClass(getApplicationContext(), A.class); 
startActivity(i); 
// finish(); its finished ChooseActivity remove it  
} 
+0

感謝您的建議,sasikumar,但我嘗試與o沒有「完成()」沒有結果 – Hern