【问题标题】:Why my application class which extends android.app.application is not working?为什么我的扩展 android.app.application 的应用程序类不起作用?
【发布时间】:2019-10-05 09:59:42
【问题描述】:

每当我的应用程序启动时,我都必须从测试类调用一个打印方法。我从扩展 android.app.application 类的 MyApplication 类的 onCreate() 调用了这个打印方法。在 print() 方法中,我显示了一条 toast 消息。但是,没有显示该敬酒消息。请帮助!

public class MyApplication extends Application 
{
    @Override
    public void onCreate() {
        super.onCreate();
        Test.print(this);
        Toast.makeText(this,"On Create  called",Toast.LENGTH_LONG).show();

    }
}


public class Test {
    static  void print(Context context)
    {
        Toast.makeText(context,"Print called",Toast.LENGTH_LONG).show();
    }
}

【问题讨论】:

  • 调试时间...

标签: java android oncreate android-application-class


【解决方案1】:

您还应该在manifest 中声明您的自定义应用程序类:

<application
    android:name=".<your packages to the class>.MyApplication"
...>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多