2015-03-25 143 views
-1

我正在編寫從其他活動啓動的活動。它獲取有時會推出新的活動顯示黑屏如果反覆退出和重新啓動屏幕Android應用程序在重複啓動並退出後顯示空白屏幕

下面這是越來越從另一個活動推出的活動中的onCreate():

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
    if (!isTaskRoot()) { 
     final Intent intent = getIntent(); 
     final String intentAction = intent.getAction(); 
     if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) { 
       Log.w("onCreate()", "Main Activity is not the root. Finishing Main Activity instead of launching."); 
      finish(); 
      return;  
     } 
    } 
    super.onCreate(savedInstanceState); 
    Log.d("onCreate()", "Calling setContentView()"); 
    setContentView(R.layout.dial_screen); 
    name = (TextView) findViewById(R.id.name); 
    number = (TextView) findViewById(R.id.number); 
    duration = (TextView) findViewById(R.id.duration); 
    mute = (Button) findViewById(R.id.mute); 
    end = (ImageButton) findViewById(R.id.end); 

} 

而且這裏是dial_screen.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:background="@drawable/bg1024_600" 
tools:context="com.harman.contacts.CallScreenActivity" > 

<TextView 
    android:id="@+id/name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="100dp" 
    android:text="@string/hello_world" 
    android:textSize="45sp" 
    android:textColor="@android:color/white" /> 
<TextView 
    android:id="@+id/number" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_below="@id/name" 
    android:layout_marginTop="50dp" 
    android:text="@string/hello_world" 
    android:textSize="35sp" 
    android:textColor="@android:color/white" /> 
<TextView 
    android:id="@+id/duration" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_below="@id/number" 
    android:layout_marginTop="50dp" 
    android:text="@string/dialling" 
    android:textSize="35sp" 
    android:textColor="@android:color/white" /> 

<LinearLayout 
    android:id="@+id/buttons" 
    android:layout_centerHorizontal="true" 
    android:layout_below="@id/duration" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_marginTop="80dp"> 

    <Button 
     android:id="@+id/mute" 
     android:layout_width="450dp" 
     android:layout_height="110dp" 
     android:text="@string/mute" 
     android:textSize="30sp" 
     android:textColor="@android:color/white" 
     android:layout_gravity="bottom"/> 
    <ImageButton 
     android:id="@+id/end" 
     android:layout_width="450dp" 
     android:layout_height="100dp" 
     android:layout_marginStart="30dp" 
     android:background="@drawable/end_call" 
     android:contentDescription="@string/hello_world" 
     android:layout_gravity="bottom"/> 
</LinearLayout> 

每次我收到日誌之前的setContentView()(這意味着活動正確啓動),但有時,即使獲取日誌後,佈局也不會顯示。 空白屏幕並不是每次都來,但有時候。任何想法,爲什麼這是和如何解決它?另外讓我知道是否需要更多信息。

+0

請讓我知道爲什麼'-1'。在發佈問題之前,我已經在網上搜索了足夠的內容。在Android默認通話應用程序中也觀察到類似的錯誤。然而,經過多次搜索,我找不到任何東西。幫助將不勝感激。 – SDG99 2015-03-25 10:56:05

+0

我也得到了類似的東西。按回退出,我有一段空白的黑屏。我不得不一直重複按下應用程序才能完全退出:-( – user3833732 2016-06-18 10:32:33

回答

0

你爲什麼不嘗試這樣

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Log.d("onCreate()", "Calling setContentView()"); 
    setContentView(R.layout.dial_screen); 
    if (!isTaskRoot()) { 
     final Intent intent = getIntent(); 
     final String intentAction = intent.getAction(); 
     if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) { 
       Log.w("onCreate()", "Main Activity is not the root. Finishing Main Activity instead of launching."); 
      finish(); 
      return;  
     } 
    } 

    name = (TextView) findViewById(R.id.name); 
    number = (TextView) findViewById(R.id.number); 
    duration = (TextView) findViewById(R.id.duration); 
    mute = (Button) findViewById(R.id.mute); 
    end = (ImageButton) findViewById(R.id.end); 

} 
+0

這沒有幫助。但是,偶爾我會在連續按下鍵並重新啓動活動後出現空白屏幕。 – SDG99 2015-03-25 10:18:30

0

仍然不知道什麼是錯的,但我發現,當我按下home鍵這個問題是不會發生的,我發現了一個變通。通過執行onBackPressed(),我使返回鍵的行爲與後退鍵相同。希望這個黑客可以幫助面臨類似問題的人:

public void onBackPressed() { 
    moveTaskToBack(true); 
} 

這不是解決方案,而是一個簡單的解決方法。我會保持這個問題的某些日子有人想出實際的解決方案

相關問題