MyApplication.java 1013 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.yxf.clippathlayout.sample;
  2. import android.app.Application;
  3. import android.content.Context;
  4. import android.widget.Toast;
  5. import com.squareup.leakcanary.LeakCanary;
  6. public class MyApplication extends Application {
  7. private static Context sAppContext;
  8. private static Toast sToast;
  9. @Override
  10. public void onCreate() {
  11. super.onCreate();
  12. if (LeakCanary.isInAnalyzerProcess(this)) {
  13. // This process is dedicated to LeakCanary for heap analysis.
  14. // You should not init your app in this process.
  15. return;
  16. }
  17. LeakCanary.install(this);
  18. sAppContext = getApplicationContext();
  19. }
  20. public static void displayToast(String message) {
  21. if (sToast == null) {
  22. sToast = Toast.makeText(sAppContext, message, Toast.LENGTH_SHORT);
  23. } else {
  24. sToast.setText(message);
  25. }
  26. sToast.show();
  27. }
  28. public static Context getAppContext() {
  29. return sAppContext;
  30. }
  31. }