Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,732,206 Members 43,561 Now Online
XDA Developers Android and Mobile Development Forum

Why my TOAST not appear?

Tip us?
 
AndreBernard
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 3
Join Date: May 2014
Default Why my TOAST not appear?

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
 
GalaxyInABox
Old
#2  
Senior Member
Thanks Meter 196
Posts: 183
Join Date: May 2013
Location: Bonn
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 GalaxyInABox For This Useful Post: [ Click to Expand ]
 
AndreBernard
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 3
Join Date: 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
 
mohamedrashad
Old
#4  
mohamedrashad's Avatar
Senior Member
Thanks Meter 415
Posts: 876
Join Date: Nov 2012
Location: ismailia
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()


Try Pi Developers apps

Socials Addict || Floata For Twitter
| | Pi locker

Check Pi Developers Blog

pidevelopers.blogspot.com


My Work For Android



 
AndreBernard
Old
#5  
Junior Member - OP
Thanks Meter 0
Posts: 3
Join Date: May 2014
Excuse me for the late answer
Thanks a lot for your help, that's works now
 
mohamedrashad
Old
#6  
mohamedrashad's Avatar
Senior Member
Thanks Meter 415
Posts: 876
Join Date: Nov 2012
Location: ismailia
Quote:
Originally Posted by AndreBernard View Post
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


Try Pi Developers apps

Socials Addict || Floata For Twitter
| | Pi locker

Check Pi Developers Blog

pidevelopers.blogspot.com


My Work For Android



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Run, Jump, and Shoot in Tales of Ciaxia

There are certain types of games that have become paramount of the portable gaming world. As we have … more

Samsung Gear Live Stock Firmware Image Pulled, Temp Root

Just yesterday,XDA Recognized Developer and TV ProducerAdamOutlertore apart … more

Draw a Line and Let Your Device Do the Rest with LineitApp

Over the years, since evenbefore Android entered the scene, we have striven to … more

[APK] Chrome Beta 37 Brings First Traces of Material Design

With Android L on the horizon, it’s no surprise that Google’s … more