NVIDIA SHIELD Tablet Gets Android 5.0.1, OTA Available

The NVIDIA SHIELD Tablet is the latest Android-powered device released by famed GPU … more

FXP Team Delivers Lollipop to Various Xperia Devices!

From all of us here at XDA-Developers, we’d like to wish you Happy Holidays! If … more

Turn Your Camera Into a Live Puzzle Game

The classic sliding puzzle game hasnt changed much, if at all, over the years. Dating all the way … more

Samsung Begins Production of 8 Gb RAM Chips

With the release of Android 5.0, our favorite mobile operating system has become 64-bit ready. … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Why my TOAST not appear?

OP AndreBernard

27th May 2014, 03:38 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
3 posts
Join Date:Joined: May 2014
Hello,

I'm newer in ANDROID and not understand why the TOAST not appear in this case.
If i comment the loop "Boucle()" that's works, else not

Code:
package com.example.toast;

import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Toast toast= Toast.makeText(MainActivity.this, "I'm a TOAST and i not appear.", Toast.LENGTH_LONG);  
		toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
		toast.show();
		
		//Boucle();
	}
	

	public void Boucle() 
	{
		
		Integer a = 0;
		
		for(int i = 1; i <= 500000; i++)
		{
			
			a++;

		}
		
	}

}
Thanks and good day
27th May 2014, 07:11 PM   |  #2  
Senior Member
Flag Cologne
Thanks Meter: 219
 
190 posts
Join Date:Joined: May 2013
More
Weird, I copied your code and it worked just fine.
You may try to replace MainActivity.this with this, as classname.this is only needed when working with nested class. And for your information: You can chain the toast call like this:
Code:
Toast.makeText(MainActivity.this, "I'm a TOAST and i not appear.", Toast.LENGTH_LONG).setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0).show();
and methods normally start with a lower case letter.
The Following User Says Thank You to giuliomvr For This Useful Post: [ View ]
27th May 2014, 08:40 PM   |  #3  
OP Junior Member
Thanks Meter: 0
 
3 posts
Join Date:Joined: May 2014
Thanks for the tips to chain the Toast, i don't know that
Tomorow i test another time, for see if it's better
Again thanks for your help
28th May 2014, 12:08 PM   |  #4  
mohamedrashad's Avatar
Senior Member
Flag ismailia
Thanks Meter: 463
 
1,002 posts
Join Date:Joined: Nov 2012
More
Code:
Toast toast= Toast.makeText( getApplicationContext() , "I'm a TOAST and i not appear.", Toast.LENGTH_LONG);  
		toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
		toast.show();
just change the MainActivity.this with getApplicationContext() or getBaseContext()
2nd June 2014, 02:29 PM   |  #5  
OP Junior Member
Thanks Meter: 0
 
3 posts
Join Date:Joined: May 2014
Excuse me for the late answer
Thanks a lot for your help, that's works now
2nd June 2014, 06:40 PM   |  #6  
mohamedrashad's Avatar
Senior Member
Flag ismailia
Thanks Meter: 463
 
1,002 posts
Join Date:Joined: Nov 2012
More
Quote:
Originally Posted by AndreBernard

Excuse me for the late answer
Thanks a lot for your help, that's works now

Pressing thanks is enough bro

Sent from my GT-S5360 using XDA Free mobile app
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes