简体   繁体   English

在 App Widget 中的 Android 中显示之前停止 Activity

[英]Stop Activity before displaying in Android in App Widget

I use a settings activity for my App Widget.我为我的 App Widget 使用设置活动。 The settings Activity has the following "Create" method.设置Activity有以下“创建”方法。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    if (!isNetworkAvailable(this)) {
        Toast.makeText(this.getApplicationContext(),"You're offline. Turn Internet on before", 
         Toast.LENGTH_LONG);
        setResult(RESULT_CANCELED);
        finish();
    }

    setContentView(R.layout.settings_activity);
...

I would like to stop the Activity before even something is displayed but to put the isNetworkAvailable(this) before the SetContentView doesn't work.我想在显示某些内容之前停止活动,但要在 SetContentView 不起作用之前放置isNetworkAvailable(this) The activity flickers for a while and then stops.活动闪烁了一会儿,然后停止。 I would like to execute this check before the App Widget executes the "Intent" and before the Activity even appears (displays) but because of the App Widget architecture I don't see a quick way to do it.我想在 App Widget 执行“Intent”之前和 Activity 甚至出现(显示)之前执行此检查,但由于 App Widget 架构,我看不到快速的方法。

Try to set your app theme to尝试将您的应用主题设置为

android:Theme.Translucent.NoTitleBar.Fullscreen

and use并使用

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    if (!isNetworkAvailable(this)) {
        Toast.makeText(this.getApplicationContext(), "You're offline. Turn Internet on before",
                Toast.LENGTH_LONG);
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    setTheme(R.style.your_theme)
    setContentView(R.layout.settings_activity);

    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM