EDIT :
*The entire issue was that since i miss-read .makeText for .makeToast, since
i have corrected this i have found that both of the previous attempts actually work for my app. *
I'm having issues implementing Toast.makeToast method in my android app :
I tried
public void onRightCardExit(Object dataObject) {
Toast.makeToast(MainActivity.this, "Right", Toast.LENGTH_SHORT).show();
}
as well as
public void onLeftCardExit(Object dataObject) {
Toast.makeToast(getApplicationContext(), "Left", Toast.LENGTH_SHORT).show();
}
On the first one i get the issue
"Can not resolve method 'makeToast.(android.Content.Context,
java.lang.String, int)' "
On the second one a similiar but just more specific pointer to my java file for the context
"Can not resolve method
'makeToast.(com.sanruza.alpak.tinderlike.MainActivity,
java.lang.String, int)' "
I understand that the correct syntax is .makeToast( context, String, int ), but i still can't get it to work.
It should be makeText instead of makeToast
Toast.makeText(context,toastMsg, Toast.LENGTH_SHORT).show();
See the docs for more info..
Please read the Google Developers link: Developers Toast Document
This snapshot should clarify your concern:
makeToast does not exist, you must use makeText.
Toast.makeText(getApplicationContext(), "Msg", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Msg", Toast.LENGTH_LONG).show();
Related
[So i have that problem that it gives me an error like:
error: incompatible types: <anonymous LocationCallback> cannot be converted to PendingIntent
LocationServices.getFusedLocationProviderClient(getActivity()).requestLocationUpdates(locationRequest, new LocationCallback() {
So how can i get over it ? I want to find the address of the user and update it. I have also fragments that i have to write "this" instead of getActivity() but it gives an error each way.]1
In the photo attached the error is shown because you have not rewritten the code completely you are missing the 3rd parameter looper
your code should be something like
LocationServices.getFusedLocationProviderClient(this).requestLocationUpdates(mLocationRequest, new LocationCallback() {
#Override
public void onLocationResult(LocationResult locationResult) {
//All your code for parsing or extracting data
}
},
Looper.myLooper());
I am getting this AIDE (Android IDE) error: "Method onRewardedVideoCompleted does not override method from superclass". The weird part is there is no errors in Android Studio. I followed this guide: https://developers.google.com/admob/android/rewarded-video
I am getting this error in AIDE:
Here is the full code: https://pastebin.com/TJCPw5BH
#Override
public void onRewardedVideoCompleted() {
Toast.makeText(this, "onRewardedVideoCompleted", Toast.LENGTH_SHORT).show();
}
All help appreciated!
I also had this issue.
This is what I did to resolve it:
In RNFirebaseAdMobRewardedVideo.java:
#Override
public void onRewardedVideoCompleted() {
// Toast.makeText(this, "onRewardedVideoCompleted",
// Toast.LENGTH_SHORT).show();
sendEvent("onRewardedVideoCompleted", null);
}
And if you receive this error after adding that code: Error:Execution failed for task ':app:transformClassesWithDexForRelease', add this to your app build.gradle:
defaultConfig {
multiDexEnabled true
}
Please let me know if this works!
Here's how I implement Toast:
if ((name == "") || (pass == "")){
Toast invalidLoginToast = new Toast.makeText(this, "aaa", 3).show();
} else {
Intent intent = new Intent (this, AnnouncementsActivity.class);
String deviceId = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
intent.putExtra("NAME", name);
intent.putExtra("ID", deviceId);
startActivity(intent);
}
But I get the error
Error:(34, 48) error: cannot find symbol class makeText
Neccessary imports are already made. Am I sending wrong parameters into the method?
Instantiate a Toast object with one of the makeText() methods. This
method takes three parameters: the application Context, the text
message, and the duration for the toast. It returns a properly
initialized Toast object. You can display the toast notification with
show();
Toast.makeText(context, text, duration)
Read official guideline about Toast .
Toast.makeText(CurrentActivityName.this,"aaa",Toast.LENGTH_SHORT).show();
Just do Toast.makeText(this, "aaa", LENGHT_SHORT).show();
This line is wrong,
Toast invalidLoginToast = new Toast.makeText(this, "aaa", 3).show();
Replace it with
Toast.makeText(this, "aaa", 3).show();
Toast is having makeText method as static, and you can call it from the class name, don't call it the way you are calling it(i.e by new operator).
For further info, please visit the official documentation
Remove new keyword in front of Toast initialization.
use
Toast invalidLoginToast = Toast.makeText(this, "aaa", 3).show();
You don't need to use new keyword while creating Toast as it is provided by factory method inside Toast which does that for you.
Instantiate a Toast object with one of the makeText() methods. This
method takes three parameters: the application Context, the text
message, and the duration for the toast. It returns a properly
initialized Toast object. You can display the toast notification with
show()
Toast.makeText(context, text, duration);
context
getApplicationContext() - Returns the context for all activities
running in application.
getBaseContext() - If you want to access Context from another context
within application you can access.
getContext() - Returns the context view only current running activity.
text
text - Return "STRING" , If not string you can use type cast.
(string)num // type caste duration
duration
Toast.LENGTH_SHORT - Toast delay 2000 ms predefined
Toast.LENGTH_LONG - Toast delay 3500 ms predefined
milisecond - Toast delay user defined miliseconds (eg. 4000)
if ((name.equals("")) || (pass.equals(""))){
Toast.makeText(this,"aaa",Toast.LENGTH_SHORT,).show();
}
Toast invalidLoginToast = new Toast.makeText(this, "aaa", 3).show();
just remove the part (Toast invalidLoginToast = new) from your coding as you don't need to create object to Toast class to access makeText function, because its static it can be accessed directly using class name itself as Toast.makeText
just write it as
Toast.makeText(this, "aaa", 3).show();
(or)
Toast.makeText(this,"aaa",Toast.LENGTH_SHORT).show();
I'm trying to implement a Google Fit Listener when data is updated into Google Fit services.
In this link of Google Fit documentation there is a simple example, however, it is not 100% clear. For that reason, I have two problems:
I don't know how to implement mResultCallback variable (there aren't any examples in this documentation).
When I define a simple ResultCallback (it seems to work but I'm not sure) and I launch the application, it gives me a result error code: java.lang.SecurityException: Signature check failed
The code within the HistortyApi lists one of android.permission.ACCESS_FINE_LOCATION or android.permission.BODY_SENSORS as being required.
Adding those permissions to my code hasn't resolved the same problem though.
Confirmed bug in Google Fit services. See discussion in https://plus.google.com/110141422948118561903/posts/Lqri4LVR7cD
mResultCallback is a ResultCallback<Status> so you need to implement a class of that type. Documentation is here, but there's only one method you need to implement:
public abstract void onResult (Status result)
The standard way is to do this using an anonymous class either when you declare mResultCallback or when you're using it as a parameter. Below is an example from Google's BasicRecordingAPI example:
Fitness.RecordingApi.subscribe(mClient, DataType.TYPE_ACTIVITY_SAMPLE)
.setResultCallback(new ResultCallback<Status>() {
#Override
public void onResult(Status status) {
if (status.isSuccess()) {
if (status.getStatusCode()
== FitnessStatusCodes.SUCCESS_ALREADY_SUBSCRIBED) {
Log.i(TAG, "Existing subscription for activity detected.");
} else {
Log.i(TAG, "Successfully subscribed!");
}
} else {
Log.i(TAG, "There was a problem subscribing.");
}
}
});
If you want to use a member variable you can simply make an assignment instead:
ResultCallback<Status> mResultCallback = new ResultCallback<Status>() {
#Override
public void onResult(Status status) {
...
}
});
Of course you can define a non-anonymous class, but if you did that for every callback you had you would end up creating a LOT of classes.
I've been working on a project to create a map (using googles api) where the user can longpress to place custom overlays. So far I've been able to allow the user to place one overlay, but when you go to place the second the program crashes. I suspect it's because the method attempts to reuse the same variable name? Here's the segment of code I'm using, any help as to how to achieve this would be greatly appreciated.
#Override
public void onLongPressFinished(MotionEvent e, ManagedOverlay overlay, GeoPoint point, ManagedOverlayItem item) {
if (item != null)
Toast.makeText(getApplicationContext(), "You selected..." + item.getTitle() + "!", Toast.LENGTH_LONG).show();
ManagedOverlay managedOverlay = overlayManager.createOverlay("listenerOverlay", getResources().getDrawable(R.drawable.tankicon));
managedOverlay.createItem(point, "text");
overlays.add(managedOverlay);
overlayManager.populate();
}
}
please try this one. This is used for showing multiple overlays on map view, may be it will solve the problem: https://github.com/donnfelker/android-mapviewballoons
To solve the problem I simply used the onDoubleTap method instead of the longPress. The longPress turned out to be way to problematic as it could be misinterpreted, and sometimes did not work.
The bulk of the code is still the same however.
#Override
public boolean onDoubleTap(MotionEvent e, ManagedOverlay overlay, GeoPoint point, ManagedOverlayItem item) {
ManagedOverlay managedOverlay = overlayManager.createOverlay("Location", getResources().getDrawable(R.drawable.icon));
managedOverlay.createItem(point, "place");
overlays.add(managedOverlay);
Toast.makeText(getApplicationContext(), "You selected " + managedOverlay.getName() + " !", Toast.LENGTH_LONG).show();
overlayManager.populate();