2017-04-05 77 views
3

我的應用程序有一個啓動畫面(無法避免它,因爲它是品牌的原因)。如何在Android中的應用程序在後臺顯示啓動畫面?

我想掩蓋用戶界面,並在後臺顯示啓動畫面(如銀行應用程序那樣)。

我應該爲MainActivity中的視圖覆蓋onPause()和onResume()嗎?

清單:

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".SplashActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/title_activity_main" 
     android:theme="@style/AppTheme.NoActionBar"></activity> 
</application> 

飛濺活動: 的onCreate()

setContentView(R.layout.splash_layout); 
new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      /* Create an Intent that will start the Main-Activity. */ 

      Intent intent = new Intent(this, MainActivity.class); 
      startActivity(intent); 
      finish(); 
     } 
    }, SPLASH_DISPLAY_LENGTH); 
} 

MainActivity():僅顯示文本和按鈕佈局

的onCreate():

setContentView(R.layout.example_view); 

現在,當我的應用程序在後臺,當我按下菜單按鈕可以看到在我的棧的應用程序列表中,我應該看到splashview(xml文件)不是deafult行爲即MainActivity佈局。

一個我嘗試了的事情是增加

getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, 
       WindowManager.LayoutParams.FLAG_SECURE); 

這確實掩蓋了應用程序時,它是在背景,白色屏幕,但我想顯示啓動視圖時,應用程序是在後臺。

我知道所有的iOS銀行應用程序都有這個功能。

編輯enter image description here

如果你看到在後臺Twitter的應用程序(例),我想掩蓋與閃屏應用程序視圖。現在使用FLAG_SECURE可以幫助我用白色屏幕屏蔽屏幕,但我想顯示飛濺佈局而不是白色屏幕。

  • 如果從iOS設備看到下面的圖片 - Discover應用程序(例如)口罩閃屏的應用程序,這可以在Android做些什麼呢?

enter image description here

+0

你想再次打開活動一次重新打開應用?如果沒有,你可以做的最好的事情就是在'onPause()'方法中調用'finish()'。 –

+0

@不,我編輯了我的問題以獲得更好的理解。 – DroidDev

回答

2

可以這樣在Android上做了什麼?

不直接,AFAIK。

我應該爲MainActivity中的視圖覆蓋onPause()和onResume()嗎?

可能不是。雖然您可以更改有你的UI:

  • 這些方法被調用其他原因(例如,當用戶點擊在多窗口模式的另一個窗口,當你啓動另一個你的活動)

  • 這可能是太晚了對於當截圖被採取

+0

整體原因是爲了確保應用程序,當它在後臺顯示啓動畫面,但因爲我沒有看到任何其他解決方案 - (使用下面的方法只是隱藏在背景中的白色空屏幕的視圖,這是我想要的部分) getWindow()。setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);' – DroidDev

+1

@ User54321:'FLAG_SECURE'將處理安全部分,儘管[它有一些泄漏](https://commonsware.com /blog/2016/06/06/psa-flag-secure-window-leaks.html)。不過,我不知道如何定製該屏幕。 – CommonsWare

相關問題