CountDownTimer problem - Java for Android App Development

Hello! I'm new to this forum. I'm developing an Android app, I have some problems with the functionality of a timer and I don't figure out why. I would need some ideas.
In my application I have 2 activities: one is with the levels of a game, where you can chose between them and the second one is with the game itself. In the second activity I have a CountDownTimer which tells me when the game must finish. I have a progressBar assigned to that timer.
CountDownTimer mCountDownTimer; -global variable
In onCreate I have:
mProgressBar=(ProgressBar)findViewById(R.id.progressBar);
mProgressBar.setProgress(0);
mCountDownTimer=new CountDownTimer(90000,1000) {
int i=0;
@override
public void onTick(long millisUntilFinished) {
Log.v("Log_tag", "Tick of Progress" + i + millisUntilFinished);
i++;
mProgressBar.setProgress(i); }
@override
public void onFinish() {
i++;
mProgressBar.setProgress(i);
Intent in = new Intent(getApplicationContext(), MyActivity2.class);
startActivity(in);
}
};
mCountDownTimer.start();
I have also overriden the native back button from Android to go to the first activity, the one with the levels and there I try to stop the counter, but it doesn't seem to work at all. The counter doesn't stop, and the other functions don't work as well.
Here is the code:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) { //Back key pressed
mCountDownTimer.cancel();
Intent in = new Intent(getApplicationContext(), MyActivity2.class);
startActivity(in);
mCountDownTimer.cancel();
return true;
}
return super.onKeyDown(keyCode, event);
}
public void onBackPressed(){
mCountDownTimer.cancel();
Intent in = new Intent(getApplicationContext(), MyActivity2.class);
startActivity(in);
return;
How could I solve this? Thank you so much!

Here is your problem:
CountDownTimer mCountDownTimer; -global variable
There are no global variables in Java, only instance variables. Since you didn't post your full code I'm going to make a few assumptions here...
public class myAwesomeTimerClass {
CountDownTimer mCountDownTimer;
// bla bla
}
Then in your second activity/class, you should refer to the class:
instead of:
mCountDownTimer.cancel();
try:
myAwesomeTimerClass.mCountDownTimer.cancel();
Good luck.

Related

[Q] Handling ACTION_SCREEN in a widget

Hi,
I'm doing a widget that needs to be update on screen_on or on
user_present. As I'm not hable to register a BroadcastReceiver inside
the widget I'm doing it in a Service that is triggered by the widget
like this:
Widget.java:
Code:
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
context.startService(new Intent(context,
WidgetService.class).setAction(WidgetService.ACTION_WIDGET_START));
}
WidgetService.java:
Code:
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
String action = intent.getAction();
Log.d(LOG_APP,"WidgetService onStart: "+action);
if (ACTION_WIDGET_STOP.equals(action)) {
this.unregisterReceiver(mReceiver);
stopSelf();
return;
} else if (ACTION_WIDGET_START.equals(action)) {
// register receiver that handles screen on and screen off logic
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
this.registerReceiver(mReceiver, filter);
return;
}
The problem is that when I try to register the receiver I get the
error that the service has leaked IntentReceiver because it was
already registered. Ive checked and no duplicate registration was done
in my code.
Do you have any idea what I'm overlooking?
Thanks,
PMD

Finish Appwidget Config Activity

i have an Appwidget that i have been working on in conjuntion with an Appwidget Config Activity that runs before the Appwidget gets placed. i have two buttons in the config activity. one for canceling out of creating the widget and one for making the widget. i am fine on the cancel button, but no matter what i do for my create button i cant seem to get it to make the appwidget.
how can i have a button create my appwidget inside my appwidget config activity?
----
ANSWER IN #3
Bump.
It would be logical to have finish() make the widget appear but it does not. Really need some help / direction with this
From something awesome
hope this helps others who are looking to make this happen.
Code:
private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(RESULT_CANCELED);
setContentView(R.layout.gitc_config);
findViewById(R.id.create_button).setOnClickListener(mOnClickListener);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
}
View.OnClickListener mOnClickListener = new View.OnClickListener() {
public void onClick(View v) {
// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
};

[Q] Dialog out of Activity

Hello app developers!
I have got serious problem. Every time I call alertdialogs or other dialogs I see them only in activity. But my app needs to show this dialog when user works on phone, that's why it must be shown out of activity. Any ideas?
DoR2 said:
Hello app developers!
I have got serious problem. Every time I call alertdialogs or other dialogs I see them only in activity. But my app needs to show this dialog when user works on phone, that's why it must be shown out of activity. Any ideas?
Click to expand...
Click to collapse
You cannot do this. There is simply no feature for that. I have had that problem, too.
Use a Notification or a Toast message.
There is a work-around for this. If you run a service, you can technically launch an activity that can resemble this.
I have an app that uses a broadcast receiver to listen for the events I want to alert my user to. I created a custom layout for my alert dialog and then when the event happens, my broadcast receiver calls the activity.
zalez said:
There is a work-around for this. If you run a service, you can technically launch an activity that can resemble this.
I have an app that uses a broadcast receiver to listen for the events I want to alert my user to. I created a custom layout for my alert dialog and then when the event happens, my broadcast receiver calls the activity.
Click to expand...
Click to collapse
Yes, great idea. Launch a transparent Activity and start a dialog. Set an onDismissListener and close the app when the dialog is closed.
nikwen said:
Yes, great idea. Launch a transparent Activity and start a dialog. Set an onDismissListener and close the app when the dialog is closed.
Click to expand...
Click to collapse
If I start a transparent activity user can't see that it was started as I understand. Can you give code for broadcast receiver maybe I misunderstand something
The broadcast receiver is just the mechanism I use to launch the activity. It is a mere intent that I start from it. Below is the class I use for my alertdialog. You won't be able to cut and paste because I also created my own class to dismiss the activity.
Code:
public class SilentDialog extends TimedActivity implements OnTouchListener{
Intent intent;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
showAlert();
}
[user=439709]@override[/user]
protected void onDestroy()
{
//this is very important here ;)
super.onDestroy();
}
public boolean onTouch(View v, MotionEvent event)
{
final int actionPerformed = event.getAction();
//reset idle timer
// put this here so that the touching of empty space is captured too
// it seems that LinearLayout doesn't trigger a MotionEvent.ACTION_UP or MotionEvent.ACTION_MOVE
if (actionPerformed == MotionEvent.ACTION_DOWN)
{
super.onTouch();
}
return false;//do not consume event!
}
public void showAlert(){
//would you like it to expire?
AlertDialog.Builder builder;
final AlertDialog alertDialog;
Context mContext = SilentDialog.this;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.pop1,
(ViewGroup) findViewById(R.id.layout_root));
NumberPicker spin = (NumberPicker) layout.findViewById(R.id.SpinRate);
spin.setVisibility(8);
TextView rate = (TextView) layout.findViewById(R.id.RateTitle);
rate.setVisibility(8);
TextView text = (TextView) layout.findViewById(R.id.txtAlertDiag);
text.setText("ButlerSMS has detected the ringer mode has changed to silent. " +
"\n\n Would you like ButlerSMS to turn on?");
final NumberPicker picker = (NumberPicker) layout.findViewById(R.id.SpinRate);
picker.setValue(60);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setTitle("ButlerSMS - Silent Mode");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
intent = new Intent(getBaseContext(), ButlerWidget.class);
intent.setAction("StartSMS");
intent.putExtra("msg","Normal");
sendBroadcast(intent);
finish();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
finish();
}
});
alertDialog = builder.create();
alertDialog.show();
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
alertDialog.dismiss(); // when the task is active then close the dialog
t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
finish();
}
}, 19000);
}
}
zalez said:
The broadcast receiver is just the mechanism I use to launch the activity. It is a mere intent that I start from it. Below is the class I use for my alertdialog. You won't be able to cut and paste because I also created my own class to dismiss the activity.
Code:
public class SilentDialog extends TimedActivity implements OnTouchListener{
Intent intent;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
showAlert();
}
[user=439709]@override[/user]
protected void onDestroy()
{
//this is very important here ;)
super.onDestroy();
}
public boolean onTouch(View v, MotionEvent event)
{
final int actionPerformed = event.getAction();
//reset idle timer
// put this here so that the touching of empty space is captured too
// it seems that LinearLayout doesn't trigger a MotionEvent.ACTION_UP or MotionEvent.ACTION_MOVE
if (actionPerformed == MotionEvent.ACTION_DOWN)
{
super.onTouch();
}
return false;//do not consume event!
}
public void showAlert(){
//would you like it to expire?
AlertDialog.Builder builder;
final AlertDialog alertDialog;
Context mContext = SilentDialog.this;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.pop1,
(ViewGroup) findViewById(R.id.layout_root));
NumberPicker spin = (NumberPicker) layout.findViewById(R.id.SpinRate);
spin.setVisibility(8);
TextView rate = (TextView) layout.findViewById(R.id.RateTitle);
rate.setVisibility(8);
TextView text = (TextView) layout.findViewById(R.id.txtAlertDiag);
text.setText("ButlerSMS has detected the ringer mode has changed to silent. " +
"\n\n Would you like ButlerSMS to turn on?");
final NumberPicker picker = (NumberPicker) layout.findViewById(R.id.SpinRate);
picker.setValue(60);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setTitle("ButlerSMS - Silent Mode");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
intent = new Intent(getBaseContext(), ButlerWidget.class);
intent.setAction("StartSMS");
intent.putExtra("msg","Normal");
sendBroadcast(intent);
finish();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
finish();
}
});
alertDialog = builder.create();
alertDialog.show();
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
alertDialog.dismiss(); // when the task is active then close the dialog
t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
finish();
}
}, 19000);
}
}
Click to expand...
Click to collapse
I understood everything except the way how app switch between position before signal came and required activity with alert dialog in it. As I see this code initialize activity and alert dialog but don't contain switching that I need
Are you asking how I call the dialog? If so, a simple intent from a broadcast receiver.
Code:
Intent i = new Intent(context, SilentDialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
I would use the AlertDialog.Builder class for compatibility.
Why not use a notification, I think that is more elegant.
Code:
public class InstalledReceiver extends BroadcastReceiver {
private NotificationManager mNotificationManager ;
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
if (BaseActivity.DEBUG) System.out.println("Received Broadcast");
Boolean update = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
mNotificationManager = (NotificationManager) context.getSystemService("notification");
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(context);
Boolean disabledNotifications = getPrefs.getBoolean("disableNotifications", false);
if (!disabledNotifications && !update) makeNotification(context);
}
private void makeNotification(Context context) {
CharSequence label = context.getString(R.string.labelNotify);
CharSequence text = context.getString(R.string.textNotify);
CharSequence full = context.getString(R.string.fullNotify);
final Notification notification = new Notification(R.drawable.ic_launcher,text,System.currentTimeMillis());
notification.setLatestEventInfo(context,label,full,null);
notification.defaults = Notification.DEFAULT_ALL;
mNotificationManager.notify( 0, notification);
}
}
Taptalked u see .. əəs n pəʞlɐʇdɐʇ
Zatta said:
Why not use a notification, I think that is more elegant.
Code:
public class InstalledReceiver extends BroadcastReceiver {
private NotificationManager mNotificationManager ;
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
if (BaseActivity.DEBUG) System.out.println("Received Broadcast");
Boolean update = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
mNotificationManager = (NotificationManager) context.getSystemService("notification");
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(context);
Boolean disabledNotifications = getPrefs.getBoolean("disableNotifications", false);
if (!disabledNotifications && !update) makeNotification(context);
}
private void makeNotification(Context context) {
CharSequence label = context.getString(R.string.labelNotify);
CharSequence text = context.getString(R.string.textNotify);
CharSequence full = context.getString(R.string.fullNotify);
final Notification notification = new Notification(R.drawable.ic_launcher,text,System.currentTimeMillis());
notification.setLatestEventInfo(context,label,full,null);
notification.defaults = Notification.DEFAULT_ALL;
mNotificationManager.notify( 0, notification);
}
}
Taptalked u see .. əəs n pəʞlɐʇdɐʇ
Click to expand...
Click to collapse
I agree, but if he wants to use a dialog, we help him to make one.
The bad thing about the dialog is that it will interrupt whatever the user is doing. This could be very annoying. And who wants to use an app which has annoying popups?
zalez said:
Are you asking how I call the dialog? If so, a simple intent from a broadcast receiver.
Code:
Intent i = new Intent(context, SilentDialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Click to expand...
Click to collapse
When I use this code activity don't shows when I am out of application. For example Handcent SMS when SMS comes to user shows up a great dialog over all windows. My aim is the same thing
DoR2 said:
When I use this code activity don't shows when I am out of application. For example Handcent SMS when SMS comes to user shows up a great dialog over all windows. My aim is the same thing
Click to expand...
Click to collapse
Start an Activity. Set a transparent layout. Show a dialog. That will result in what you want.
nikwen said:
Start an Activity. Set a transparent layout. Show a dialog. That will result in what you want.
Click to expand...
Click to collapse
I have used this code
Code:
Intent i = new Intent(context, SilentDialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
and made transparent layout with dialog, but my dialog appears only in my app
DoR2 said:
I have used this code
Code:
Intent i = new Intent(context, SilentDialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
and made transparent layout with dialog, but my dialog appears only in my app
Click to expand...
Click to collapse
Could you please post your code?
nikwen said:
Could you please post your code?
Click to expand...
Click to collapse
How I call activity
Code:
if(answer.contains("BEEP")){
Intent intent=new Intent();
intent.setAction("Navi_Beep");
sendBroadcast(intent);
r.play();
Intent i = new Intent(context, NBeep.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
NBeep.java
Code:
public class NBeep extends Activity {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
Log.d("NaviBeep","Here");
//super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent();
intent.setAction("Navi_BeepOff");
sendBroadcast(intent);
finish();
}
});
// Set the Icon for the Dialog
alertDialog.show();
}
}
DoR2 said:
How I call activity
Code:
if(answer.contains("BEEP")){
Intent intent=new Intent();
intent.setAction("Navi_Beep");
sendBroadcast(intent);
r.play();
Intent i = new Intent(context, NBeep.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
NBeep.java
Code:
public class NBeep extends Activity {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
Log.d("NaviBeep","Here");
//super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent();
intent.setAction("Navi_BeepOff");
sendBroadcast(intent);
finish();
}
});
// Set the Icon for the Dialog
alertDialog.show();
}
}
Click to expand...
Click to collapse
Ah. You need to call setContentView. Create a transparent View and pass it as a parameter.
nikwen said:
Ah. You need to call setContentView. Create a transparent View and pass it as a parameter.
Click to expand...
Click to collapse
Doesn't help:
Code:
public class NBeep extends Activity {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
Log.d("NaviBeep","Here");
View view=new View(this);
view.setBackgroundColor(Color.TRANSPARENT);
setContentView(view);
super.onCreate(savedInstanceState);
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent();
intent.setAction("Navi_BeepOff");
sendBroadcast(intent);
finish();
}
});
// Set the Icon for the Dialog
alertDialog.show();
}
}
If you use another layout, is the Activity opened?
Is the "Here" written to the log? Is there any Error message?
And I recommend configuring the AlertDialog within the AlertDialog.Builder: http://www.mkyong.com/android/android-alert-dialog-example/
(However, I guess that it will not solve your problem.)
nikwen said:
If you use another layout, is the Activity opened?
Is the "Here" written to the log? Is there any Error message?
And I recommend configuring the AlertDialog within the AlertDialog.Builder: http://www.mkyong.com/android/android-alert-dialog-example/
(However, I guess that it will not solve your problem.)
Click to expand...
Click to collapse
I finally made it!:victory: Here is code:
1) Call dialog:
Code:
NBeep.createDialog(NBeep.DIALOG_ERROR, context);
2) NBeep.java
Code:
public class NBeep extends Activity{
public final static int DIALOG_ERROR = 4;
protected Dialog onCreateDialog(int id) {
Dialog dialog;
switch(id) {
case DIALOG_ERROR:
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent();
intent.setAction("Navi_BeepOff");
sendBroadcast(intent);
finish();
}
});
alertDialog.setCancelable(false);
dialog = alertDialog;//new AlertDialog.Builder(this).setMessage("ERROR! This is a global dialog\n Brought to you by Sherif").create();
break;
default:
dialog = null;
}
return dialog;
}
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showDialog(DIALOG_ERROR);
}
public static void createDialog(int dialog, Context context){
Intent myIntent = new Intent(context, NBeep.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}

[Q] How do I display text from a messgae into a toast?

Hi all skilled developers,
I am a newbie in coding, and I just want to make some small changes to my app.
It is a licensing feature.
1) Licensee information are stored at a very simple website. With columns for Names, IMEI and Remarks.
2) I have the following chunk of code:
Code:
if(hadLicense) {
new AlertDialog.Builder(InsuranceGuruSplash.this)
.setTitle("License")
.setMessage("Your device is registered.\nWelcome.")
.setPositiveButton("Send", new DialogInterface.OnClickListener()
Intent intent = new Intent(InsuranceGuruSplash.this, MainActivity.class);
startActivity(intent);
finish();
I want to show a toast saying,
Welcome, Shawn. Your device is registered till DD/MM/YY.
Click to expand...
Click to collapse
Can someone teach me how I can go about doing this?:silly:
You can show a toast using:
Code:
Toast.makeText(context, text, duration).show();
Just make the text String first with the text and time. For duration use Toast.LENGTH_SHORT
SimplicityApks,
Thanks for your reply. I still don't really know what you mean. how do I echo a text from a website into the app's toast?
This is the full code:
Code:
protected Void doInBackground(Void... params) {
String url_for_sale = "www(dot)heyfellas(dot)com/guru/index.php";
parseLicense(url_for_sale);
return null;
}
@Override
protected void onPostExecute(Void result) {
TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
final String imei = mngr.getDeviceId();
boolean hadLicense = false;
for(LicenseInfo license: licenses) {
if(license.phoneIMEI.equals(imei))
hadLicense = true;
}
if(hadLicense) {
Intent intent = new Intent(InsuranceGuruSplash.this, MainActivity.class);
startActivity(intent);
finish();
} else {
new AlertDialog.Builder(InsuranceGuruSplash.this)
.setTitle("License")
.setMessage("Your device is not registered.\nPlease send your details to the admin.")
.setPositiveButton("Send", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "Request for license");
i.putExtra(Intent.EXTRA_TEXT , "UserName: \n\nPhone Number: \n\nEmail: \n\nIMEI: " + imei);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(PropertyGuruSplash.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.create().show();
}
}
}
You need
[java]
String name = ...;
String date = ....;
Toast.makeToast(Activity.this, name + ", you have registered since "+date, Toast.LENGTH_SHORT).show();[/java]
I suppose, you are strong at server side than in client programming? Then echo the result in your desired format in your php and read it in java then display it in toast. Use the below snippet:
Code:
HttpClient httpclient=new DefaultHttpClient();
HttpPost httppost=new HttpPost("http://www(dot)heyfellas(dot)com/guru/index.php");
HttpResponse response = httpclient.execute(httppost);
String Result = EntityUtils.toString(response.getEntity());
Toast.makeText(Context, Result, Toast.LENGTH_SHORT).show();

Trying to make a session timer with a camera timer

Hello all ,
i'm trying to make a timer that will kick the user out after let's say a few seconds , i used asynctask for it
it supposed to work on all activities including one that uses a camera on a diffrent thread ( using vuforia api and needs internet )
for some reason when i do it the camera doesn't work
(the same thing happens when there is no internet connection - might be related)
any ideas why ?
here's my asynctask
Code:
private class LoadSessionASYNC extends AsyncTask<String, Void, String> {
long time;
long interval;
public LoadSessionASYNC(long seshTime, long interval) {
time = seshTime;
interval=inter;
}
@Override
protected String doInBackground(String... urls) {
while (time >0)
{
publishProgress();
try {
Thread.sleep(interval);
} catch (InterruptedException e) {e.printStackTrace();}
time= time-interval;
}
return null;
}
@Override
protected void onPostExecute(String result) {
Intent startfresh = new Intent(getBaseContext(),WelcomActivity.class);
startActivity(startfresh);
}
@Override
protected void onProgressUpdate(Void... values) {
Toast.makeText(getApplicationContext(), "time to finish : "+time/1000+"seconds", Toast.LENGTH_SHORT).show();
super.onProgressUpdate(values);
}
}

Categories

Resources