java

Swap two integers

public class Swapvalues {

public void swapInts(int x, int y)
{
System.out.println(“before X =”+x+”Y=”+y);
x = x + y;
y = x – y;
x = x – y;
System.out.println(“after X =”+x+”Y=”+y);
}

public static void main(String args[])
 {
Swapvalues vSwapvalues = new Swapvalues();
vSwapvalues.swapInts(7, 8);
 }
}

How to analyse Memory Availability of Android Testing Project

Both approaches worked for me, please using any of your choice,

Getting Runtime Memory using Runtime

static void checkMemory() {

double vTotalMem = Double.valueOf(Runtime.getRuntime().totalMemory());
double vMaxMem = Double.valueOf(Runtime.getRuntime().maxMemory());
double vAvailableMem = Double
.valueOf(Runtime.getRuntime().freeMemory());
print(“Runtime Memory info: TotalMem=”
+ Math.round(vTotalMem / 1048576) + “mb. MaxMemory”
+ Math.round(vMaxMem / 1048576) + ” mb. AvailableMemory=”
+ Math.round(vAvailableMem / 1048576) + ” mb.”);

}
Getting Memory using ActivityManager 

static void checkMemory() {
              ((ActivityManager)solo.getCurrentActivity()
                        .getSystemService(“activity”)).getMemoryInfo(mi);
              print(“Kernal Memory info: AvailableMemory=”+mi.
                         availMem/1048576+“mb IsMemLow=”+mi.lowMemory);
        if(mi.lowMemory) print(“memory is increasing”);
              else print(“Memory condition is fine”);
 
}

How to get All TextViews in each row of a ListView using Robotium

public void printAllTextViewsByRowIntoListView(){
vListView = solo.getCurrentViews(ListView.class).get(0);
        if (vListView.getCount() > 0) 
        {
          for (int i = 1; i <= vListView.getLastVisiblePosition(); i++) 
         
          vListRow = vListView.getChildAt(i);
          vTextViewsInListRow = solo.getCurrentViews(TextView.class, vListRow); 
          print(“Row #”+i+” contents “);
          for (int j = 0; j < vTextViewsInListRow.size(); j++) 
          { 
          print(vTextViewsInListRow.get(j).getText().toString());
          }
          print(“………”);
          }
        }
          else print(“No contents available”);
}