How to get context in JUnit4

I have a class: public class Unit { private int id; private String unit; private String dimension; private Float factor; private Context ctx; public Unit(Context context){ this.ctx = context; } public Unit(String unit, String dimension, Float factor, Context context) { super(); this.ctx = context; setUnit(unit); setDimension(dimension); setFactor(factor); } public void setDimension(String d) { String[] dimensions = ctx.getResources().getStringArray(R.array.dimensions_array); if(!Arrays.asList(dimensions).contains(d)){ throw new…
Read more

Call finish from onPause or onStop when the user destroys the app

Coclusion: onDestroy() is not always being invoked. Here is the case: After Launching the app, the MainActivity is created which starts background tracking service. On the other hand, the user can use a checkbox list in the main activity to select his interested routes where the items of the checkbox list represents the routes. After clicking the submit button, the…
Read more

how to avoid EventBus Exception (Android)?

I”m working on existing application and they are using EventBus that get every network exception like this : public void onEvent(final NetworkErrorEvent event) { runOnUiThread(new Runnable() { @Override public void run() { Log.e(“EventBus Event” + “(IOException)”); if (event.getType() == NetworkError.Timeout) { L.e(“timeout”); } else if (event.getType() == NetworkError.Disconnected) { L.e(“disconnected”); } else if (event.getType() == NetworkError.UnknownHost) { L.e(“UnknownHost”); } showConnectionErrorDialog(event.getType(),…
Read more

Refresh the display of an activity when it is visible again

I have two activities ( and, on which one fragment ( is a radio group with four buttons to select a language of translation. The parent of GrammarActivity is TextActivity. I can select the language I want either on TextActivity or GrammarActivity. And I can change it on whichever ativity I am as well. But if I select a…
Read more

Android mp3 player with listview

I want to display all the mp3 files from Devices internal memory as well as from ExtSD Card using ListView. How i can i display this, can any one give me complete working code for Java And XML files. Source: android

How to remove shadow from dialog? android

I am using AppCompatDialog to build dialog interface. My goal is remove shadow around dialog view when it shows? here is example of code: private void showWrongLoginPassDialog(String message){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.ad_login_error_title)); builder.setMessage(message); builder.setPositiveButton(getString(R.string.ad_login_error_positive), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } });; } Source: android

How do I customize timepicker to only show/set hours 1-12 without (am/pm and minutes) API 19 and disable Listeners

i want to use a TimePicker to show the position of a medical phenomenon in context to the human body. Example: Person A has a wound on his right foot at 7 o’clock. (For picture of right foot inner side) For this I want to use a TimePicker that uses the clock display and only enable hours from 1-12 and…
Read more