I solved this by Singletone pattern using.
public class StringSingletone {
static int i;
String []a;
private static StringSingletone instance;
LinkedList<String> quotes ;
// Private constructor prevents instantiation from other classes
private StringSingletone(Context context) {
a = context.getResources().getStringArray(R.array.quotes);
quotes = new LinkedList<String>(Arrays.asList(a));
Collections.shuffle(quotes);
}
/**
* SingletonHolder is loaded on the first execution of Singleton.getInstance()
* or the first access to SingletonHolder.INSTANCE, not before.
*/
public static StringSingletone getInstance() {
return instance;
}
public static void initInstance(Context context)
{
if (instance == null)
{
// Create the instance
instance = new StringSingletone(context);
}
}
private void remakeObj(Context context)
{
a = context.getResources().getStringArray(R.array.quotes);
quotes = new LinkedList<String>(Arrays.asList(a));
Collections.shuffle(quotes);
}
public String getRandomString(Context context)
{
if (quotes.size()==0)
{
remakeObj( context);
}
String l = quotes.pop();
return l;
}
}