简体   繁体   English

Firebase java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代)

[英]Firebase java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

I read many similar questions but couldn't figure out how to solve my problem. 我读过许多类似的问题,但不知道如何解决我的问题。

I got this class where I receive cloud-messaging notifications from firebase: 我在从Firebase接收云消息通知的地方上了这节课:

public class FirebaseMessagingServiceImpl extends FirebaseMessagingService {

    private final static String TAG = "FirebaseMessaging";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.i(TAG, "Message from " + remoteMessage.getFrom());
        if (remoteMessage.getNotification() != null) {
            final String content = remoteMessage.getNotification().getBody();
            final String title = remoteMessage.getNotification().getTitle();
            Log.i(TAG, "...with content: " + content);

            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    UserInterfaceUtils.getAlertDialog(
                            getApplicationContext(),
                            title,
                            content,
                            android.R.string.ok,
                            android.R.string.no,
                            android.R.drawable.ic_dialog_alert,
                            null, null,
                            true, false).show();
                }
            });
        }
        super.onMessageReceived(remoteMessage);
    }

    @Override
    public void onDeletedMessages() {
        super.onDeletedMessages();
    }
}

From there I want to create an alert.dialog . 从那里我要创建一个alert.dialog But I get this IllegalStateException . 但是我得到了这个IllegalStateException When I log the string of the getApplicationContext() I get this: android.support.multidex.MultiDexApplication@42585d08 当我记录getApplicationContext()的字符串时,我得到的是: android.support.multidex.MultiDexApplication@42585d08

I am very stuck here and have no clue how to solve this. 我很困在这里,不知道如何解决这个问题。

For completeness here my getAlertDialog-method: 为了完整起见,我的getAlertDialog方法:

public static AlertDialog.Builder getAlertDialog(Context context, String title, String message, int pos, int neg, int icon, final Callable posFunc, final Callable negFunc, boolean posButton, boolean negButton) {
        AlertDialog.Builder builder;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder = new AlertDialog.Builder(context, R.style.ShopDialogTheme);
        } else {
            builder = new AlertDialog.Builder(context);
        }

        builder.setTitle(title)
                .setMessage(Html.fromHtml(message));

        if (posButton)
            builder.setPositiveButton(pos, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        posFunc.call();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        if (negButton)
            builder.setNegativeButton(neg, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        negFunc.call();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        builder.setCancelable(false);
        builder.setIcon(icon);
        return builder;
    }

根据标题,听起来好像代码运行时您拥有的任何Activity都在扩展Activity,并且它需要扩展AppCompatActivity,并且您在res / styles.xml中使用的任何主题都应该是AppCompat主题。

暂无
暂无

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

相关问题 java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代) - java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity 错误:java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代) - Error :java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity java.lang.IllegalStateException您需要在此活动中使用Theme.AppCompat主题(或后代) - java.lang.IllegalStateException You need to use a Theme.AppCompat theme (or descendant) with this activity java.lang.IllegalStateException:您需要在此活动中使用 Theme.AppCompat 主题(或后代)。 钛 - java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. titanium java.lang.IllegalStateException:此活动需要使用Theme.AppCompat主题(或后代) - java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity 外部库用法-> java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代) - external library usage --> java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity 如何解决:java.lang.IllegalStateException:您需要在此活动中使用 Theme.AppCompat 主题(或后代)? - How to resolve: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity? Android:java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代) - Android: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity java.lang.IllegalStateException:您需要在 Flutter App 中使用 Theme.AppCompat 主题(或后代)与此活动 - java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity in Flutter App 定制主题android崩溃原因:java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代) - Crash with custom theme android Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM