Skip to main content

Posts

Save Arraylist in SharedPreferences

If you have a not so large list of string and you dont want to use SQLite for it then SharedPreferences can do the job.  
Recent posts

Graphics and Animations Part 2 : ListView Animations

If you are using listviews in your app and using animations on click of the view then you must consider the fact that views are getsmrecycled in a listview. To say it simply, if the screen can show 10 items in a listiew at once , then there are 10 views are instantiated for that listview regardless of the total number of items. Thus when you scroll a listview, the views that goes off the screen are recycled and that reference is used to show views coming in the screen. Thus understand that any animation you doing on a view may apply to other item if the listview is scrolled and that particular item goes out of stage. To avoid that you can chose two options according to the type of animation you are using. Below code demonstates that

Use a content provider

Its like bridge/proxy between java db and our/other app.   if content provider is there for a db then its really easy to access data from the db without coding directly for the db. Content resolver is provides the info for Content provider for where to access the info. A URI is needed to connect between the two.   Initial steps are to create three classes: Contract, Database and Provider Database class handles the actual db i.e CRUD operations Contract class contains all the info that is required by the Content Provider. Each content provider shold have a separate contract class.   Contract class explanation so its contains the interface containg column names of the table which are supposed to be accessed. then the name of Content authority for the Content provider (e.g org.example.myapp.provider) then the URI is to built which starts as “content://+CONTENT_AUTHORITY” as the base URI then the path i.e the table name then we have array of strings contain...

Making asynctasks rotation proof

package com.mango.rotationproof; import android.app.Activity; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; /** * Created by Avinash on 21-05-2015. */ public class TaskFrag extends Fragment { MyTask myTask; Activity activity; public TaskFrag() { } public void begintask() { myTask=new MyTask(activity); myTask.execute(); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public void onAttach(Activity activity) { super.onAttach(activity); this.activity=activity; if(myTask!=null) { myTask.onA...