在清单中添加两个不同类型的应用程序类

时间:2016-08-22 05:23:01

标签: android android-manifest

// Google Analytics class

public class MyApplication extends AppApplication {
    public static final String TAG = MyApplication.class
            .getSimpleName();

    private static MyApplication mInstance;

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;

        AnalyticsTrackers.initialize(this);
        AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP);
    }

    public static synchronized MyApplication getInstance() {
        return mInstance;
    }

    public synchronized Tracker getGoogleAnalyticsTracker() {
        AnalyticsTrackers analyticsTrackers = AnalyticsTrackers.getInstance();
        return analyticsTrackers.get(AnalyticsTrackers.Target.APP);
    }

    /***
     * Tracking screen view
     *
     * @param screenName screen name to be displayed on GA dashboard
     */
    public void trackScreenView(String screenName) {
        Tracker t = getGoogleAnalyticsTracker();

        // Set screen name.
        t.setScreenName(screenName);

        // Send a screen view.
        t.send(new HitBuilders.ScreenViewBuilder().build());

        GoogleAnalytics.getInstance(this).dispatchLocalHits();
    }

   
    public void trackException(Exception e) {
        if (e != null) {
            Tracker t = getGoogleAnalyticsTracker();

            t.send(new HitBuilders.ExceptionBuilder()
                    .setDescription(
                            new StandardExceptionParser(this, null)
                                    .getDescription(Thread.currentThread().getName(), e))
                    .setFatal(false)
                    .build()
            );
        }
    }

    
    public void trackEvent(String category, String action, String label) {
        Tracker t = getGoogleAnalyticsTracker();

        // Build and send an Event.
        t.send(new HitBuilders.EventBuilder().setCategory(category).setAction(action).setLabel(label).build());
    }

}
// my application class which extends MultiDexApplication 



public class AppApplication extends MultiDexApplication {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }



	@Override
	public void onCreate() {
		super.onCreate();
		
		

		
	}
	public static void checkrating(final Activity activity){
       
		 new Handler().postDelayed(new Runnable() {

				@Override
	   			public void run() {
	   				checkratingdialog(activity);
	   			}
	   		}, 10000 /*300000*/);
	}
	
	public static void checkratingdialog(Activity activity) {
		
		try {
			if(activity==null){
				Log.v("activity",   "null");
			}
			Calendar cal = Calendar.getInstance();
		    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
		    String currentdate = sdf.format(cal.getTime());
		    Log.v("Current date", currentdate);
		    
			SharedPreferences sharedPreferences = activity.getSharedPreferences(
					"MY_SHARED_PREF", MODE_PRIVATE);
			String shareddate  = sharedPreferences.getString("PREVIOUS_RATING_DATE", "");
			
			Log.v("Shared Date", shareddate + "");



            if(shareddate.equals("")){
				Log.v("Shared Date",  "Shared blank");
				showWaitingnooftickitsDialog(activity);

                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putString("PREVIOUS_RATING_DATE", currentdate);
                editor.commit();


			}else{
				
				int dayes =  get_count_of_days(currentdate , shareddate); 
				Log.v("dayes",  dayes+"");
				/*int dayescheck =  get_count_of_days(currentdate , "20/05/2016"); 
				Log.v("dayescheck",  dayescheck + "");*/
				if(dayes>=30){
					showWaitingnooftickitsDialog(activity);

                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putString("PREVIOUS_RATING_DATE", currentdate);
                    editor.commit();
				}
			}
			

		    
		    
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
	}

	static Dialog ratingdialog; 
   
}

我有一个扩展MultiDexApplication的Application类和扩展应用程序的另一个。我想在清单的应用程序标签中注册两个类名。我搜索了它,发现我们可以使用多级继承,如here所示。但是,如果一个是普通的Application类,另一个是MultiDexApplication类,那么如何注册这两个类?

1 个答案:

答案 0 :(得分:1)

您可以在现有应用程序类中添加以下方法以支持Multidex文件 -

protected void attachBaseContext(Context base) {
  super.attachBaseContext(base);
  MultiDex.install(this);
}