Error:Execution failed for task ‘:app:transformClassesWithDexForDebug’. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

Sometimes application may be big in execution or heavy that time multidex should be enabled .

Here is the full process to enable multidex in android

 

Enable Multidesk

Android create border radius for Button , Views , EditText and others

Step – 1: Create xml layout in drawable folder




<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:state_pressed="true" >
     <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#5e7974" />
         <gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92"  />            
     </shape>
 </item>
<item android:state_focused="true">
     <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#5e7974" />
         <solid android:color="#58857e"/>       
     </shape>
 </item>  
<item >
    <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#5e7974" />
         <gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />            
     </shape>
 </item>
</selector>

Step 2 : Implement on anywhere like button and view .

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:textColor="#ffffff"
    android:background="@drawable/mybutton"
    android:text="Buttons" />

Android Fragment basic code structure

public class BasicFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.basic_fragment_layout, container, false);
        return view;
    }
}

IOS best network image download library – SDWebImage , Swift 3/4

Sometimes network image doest not download and for that app may crash . To avoid this you can use SDWebImage library as like Picasso android library which will show a default placeholder image until file downloaded .

To implement SDWebImage –

Step 1 :

paste the pod file in podfile of your project (If you don’t create pod file . create it with ‘pod init’ command in your project directory)

 pod 'SDWebImage', '~> 4.0'

Run command

  pod install

Step 2 :

Attach your image view

let image_url = "your_image_url"

   image_view.sd_setImage(with: URL(string: image_url ), placeholderImage: UIImage(named: "AppIcon"))

Here ,

image_view is your ImageView reference . AppIcon is default placeholder .

 

Run your . Done .

 

 

 

Android back pressed to exit the app dialog and exit app

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


    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setMessage("Are you sure you want to exit the app?");
    alertDialogBuilder.setPositiveButton("yes",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_HOME);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
                    startActivity(intent);
                    finishAffinity();
                    finish();
                    System.exit(0);
                }
            });

    alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();


}

Android custom date picker

Step -1 :

Create a custom fragment

import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;

import java.text.SimpleDateFormat;
import java.util.Calendar;


@SuppressLint("ValidFragment")
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {


    public static final String DATE_FORMAT = "dd-MM-yyyy";
    EditText mView;

    private DatePickerDialog datepic;

    public DatePickerFragment(View v) {
        mView = (EditText) v;
    }


    Calendar c;

    public DatePickerFragment() {
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current date as the default date in the picker
        c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);


        datepic = new DatePickerDialog(getActivity(), this, year, month, day);
        DatePicker dp = datepic.getDatePicker();
        dp.setMinDate(c.getTimeInMillis() + 60 * 60 * 24 * 1000);
        dp.setMaxDate(c.getTimeInMillis() + 60 * 60 * 24 * 1000 * 16);
        return datepic;
    }


    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {


        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, monthOfYear);
        c.set(Calendar.DAY_OF_MONTH, dayOfMonth);

        // String years=Integer.toString(dayOfMonth);

        updateDateButtonText((EditText) mView);


    }

    private void updateDateButtonText(EditText mView) {

        SimpleDateFormat timeFormat = new SimpleDateFormat(DATE_FORMAT);
        String timeForButton = timeFormat.format(c.getTime());
        mView.setText(timeForButton);
    }


}

Step 2 : Create an EditText and call it in activity .Like this

private EditText dob;
dob = findViewById(R.id.date_of_birth);

Step 3 :
Create a click listener of dob

dob.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        DialogFragment fragment = new DatePickerFragment(dob);
        fragmentTransaction.addToBackStack(null);
        fragment.show(fragmentTransaction, "Set Date");
    }
});

Step 4 : set dob text to dob edittext

dob.setText(dob.getText().toString());

IOS Swift 3/4 show alert for specific time duration

   let alert = UIAlertController(title: "", message: "alert disappears after 30 seconds", preferredStyle: .alert)

            self.present(alert, animated: true, completion: nil)

            // change to desired number of seconds (in this case3 0 seconds)

            let when = DispatchTime.now() + 30

            DispatchQueue.main.asyncAfter(deadline: when){

                // your code with delay

                alert.dismiss(animated: true, completion: nil)

            }