Code example for Constructor

Methods: newInstance, setAccessible

0
     * @return The {@link PreferenceManager} used by this activity. 
     */ 
    private PreferenceManager onCreatePreferenceManager() {
        try{ 
            Constructor<PreferenceManager> c = PreferenceManager.class.getDeclaredConstructor(Activity.class, int.class);
            c.setAccessible(true);
            PreferenceManager preferenceManager = c.newInstance(this.getActivity(), FIRST_REQUEST_CODE);
            return preferenceManager;
        }catch(Exception e){
            e.printStackTrace();
            return null; 
        } 
    } 
     
    /** 
     * Returns the {@link PreferenceManager} used by this activity. 
     * @return The {@link PreferenceManager}. 
     */ 
    public PreferenceManager getPreferenceManager() {
        return mPreferenceManager;
    }