[Solved] How to use shared preference to send data from activity to fragment?

If you insist on shared preference use this code : To save the data private void saveSp(String key , String value){ PreferenceManager.getDefaultSharedPreferences(Context) .edit() .putString(key, value).apply(); } To get your data: PreferenceManager.getDefaultSharedPreferences(Context).getString(“string”, “default”) solved How to use shared preference to send data from activity to fragment?

[Solved] How to commit a shell command via Java [closed]

You can use like this (netstat is only dummy command. you can write whatever you want) ; String command = “cmd.exe /c start ” + “netstat”; Process child = Runtime.getRuntime().exec(command); after that you can get as data stream from child process. Or you can close the cmd also with child.destroy() method forexample. 1 solved How … Read more

[Solved] Is it somehow possible to check if points `x` and `y` is in a line when only the y-intercept and the slope is given? [closed]

Yes, it is possible, however, this has nothing to do with programming and is more of a mathematical question. (I would recommend going here https://math.stackexchange.com/) Solving this using basic Algebra, given the slope and y-intercept we can check if a point is on a line by substituting the x and y values. For example, if … Read more

[Solved] I have a string with a number and a letter, is there a way to move the integer into a separate int variable? [closed]

You could split over a specific string (degree character for example), store in a String array and parse the first element. Something like this: String str = “47°C” String[] strArray = str.split(“°”); int number = Integer.parseInt(strArray[0]); solved I have a string with a number and a letter, is there a way to move the integer … Read more

[Solved] Converting String to Double in Java [closed]

GPA = Double.parseDouble(df.format (((double)qualityPoints) /(double)(sumOfHours))); int qualityPoints = 0; int sumOfHours = 0; double GPA = 0; DecimalFormat df = new DecimalFormat(“0.00”); GPA = Double.parseDouble(df.format (((double)qualityPoints) /(double)(sumOfHours))); No compilation error for this. 8 solved Converting String to Double in Java [closed]

[Solved] No match for Java Regular Expression

Your content contains no ” quotes, and no text gm, so why would you expect that regex to match? FYI: Syntaxes like “foo”gm or /foo/gm are something other languages do for regex literals. Java doesn’t do that. The g flag is implied by the fact that you’re using a find() loop, and m is the … Read more

[Solved] Java: using .contains but returns two values [closed]

Possible solution In order to solve your problem, use string.startsWith() instead of string.contains(): if (order.startsWith(pizzaSize[0])) { /* medium */ } else if (order.startsWith(pizzaSize[1])) { /* large */ } else { /* unexpected input */ } This works because the first letter always indicates the pizza size. You can stick to using contains() for the toppings. … Read more

[Solved] Create Toast by a static method

Use this: public static void showToast(Context context, String text) { Toast.makeText(context, text, Toast.LENGTH_LONG).show(); } now for calling this method you should call like this: ClassName.showToast(context,”text”); Here classname is class that containing static method. 0 solved Create Toast by a static method

[Solved] I am trying to have an MQTT protocol in android studio. I have also updated gradle.properties [closed]

Duplicate file error comes when you have added the dependency jar to build.gradle file and also you are having same .jar file in your libs folder. To eliminate this error try to have only one thing, either have it in your build.gradle or in locally in your libs folder. 0 solved I am trying to … Read more

[Solved] Recursive java program doesn’t return any value. Putting a print statement right before the return statements prints infinite values

Recursive java program doesn’t return any value. Putting a print statement right before the return statements prints infinite values solved Recursive java program doesn’t return any value. Putting a print statement right before the return statements prints infinite values