title: Using common function in multiple activity android
body: <p>I want to use <code>common function</code> in <code>multiple activity</code>. How can I achieve this?</p>
  
  <p>In my application I am displaying a <code>Dialog box</code> which have some data coming from some api. And this Dialog box, used in multiple activities. <code>Right now I have implemented same Dialog box in all activities</code>. Now I want common Dialog box for all activities. <code>I am using this Dialog box in activity as well in adapter</code>.</p>
  
  <p>How could I do this? Using <code>extends</code> or using <code>fragment</code>.
  I am already extending some class so I can not extend again( As I read, we can not extends more than one class.). </p>
  
  <p>Also I want to pass some value to this function and based on <code>return</code> value I want to call another function.</p>
  
  <pre><code>private boolean allGroupsEdit(final String type) {
      String allGroups = "allGroups";
      final String url = Constants.CONSTANT_SERVER_URL + Constants.CONSTANT_GET_GROUPS_URL;
      final ProgressDialog dialog = new ProgressDialog(context);
    dialog.setMessage(context.getResources().getString(R.string.please_wait));
      dialog.show();
  
      StringRequest allGroupsRequest = new StringRequest(Request.Method.POST, url, new Response.Listener&lt;String&gt;() {
          @Override
          public void onResponse(String s) {
              final SharedPreferences sharedPreferencesRemember = PreferenceManager.getDefaultSharedPreferences(context);
              sessionGroupId = sharedPreferencesRemember.getString(Constants.CONSTANT_session_group_id, "");
  
              try {
                  JSONObject jsonObject = new JSONObject(s);
                  JSONArray jsonArray = jsonObject.optJSONArray(Constants.CONSTANT_data);
                  int a = jsonArray.length();
                  for (int i = 0; i &lt; jsonArray.length(); i++) {
  
                      JSONObject schObj = jsonArray.optJSONObject(i);
                      schData = schObj.optJSONArray(Constants.CONSTANT_data);
                  }
              dialog.dismiss();
                  final Dialog dialog = new Dialog(context);
                  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                  dialog.setContentView(R.layout.dialog_checkbox_options);
                  Window window = dialog.getWindow();
                  window.setLayout(DrawerLayout.LayoutParams.MATCH_PARENT, DrawerLayout.LayoutParams.WRAP_CONTENT);
  
                 if(..someting){
                   editPublicComments(type);
                 }else{
                   editPublicPosts(type);
                 }
                }catch(){}
         }
    }
  </code></pre>
  
  <p><strong>Note:</strong> This a very long function so I am pasting some code for basic understand. If u need anything more detail let me know. Thanks in advance and editing and suggestions are welcome.</p>
  
  <p><strong>Edit_1:</strong> I want this whole function to be common.
  <strong>Edit_2:</strong> How to return value to activity from utils ?</p>
  
  <p><strong>Edit_3:</strong> Now I created a static function in a class and I am able to call it from my activity. Now I want call another function based on common function result. (I am using <code>SharedPreferences</code> to store value of common function).</p>
  
  <p>But in my activity where I called a common function, I doesn't execute common function first. It call another function then It call common function and after completing common method, it doesn't call another method again.</p>
  
  <p>All I want to call another function based on result of common function which is <code>true or false</code></p>
  
  <pre><code> boolean abab = CommonGroupBox.allGroupsEdit(context,"share", selectedPostId, localGrpArray);
   if (abab){
     boolean pubFlag = pref.getBoolean("isPublicFlag", false);
     String qType = pref.getString("questionType","0");
     if (pubFlag) {
        editPublicComments(qType);
     }else{
        ediComments(qType);
     }
   else{
     boolean pubFlag = pref.getBoolean("isPublicFlag", false);
     String qType = pref.getString("questionType","0");
     if (pubFlag) {
       PublicComments(qType);
     }else{
       Comments(qType);
     }
    }
  </code></pre>
  
  <p>Here it doesn't call <code>CommonGroupBox.allGroupsEdit</code> firsts. It is called after if and else loop. </p>