This dialog asks whether you want to install some other app...so when onclicked no button it must go back to the previous screen
downloadDialog.setNegativeButton(stringButtonNo,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
this gives the error:
The method finish() is undefined for the type new DialogInterface.OnClickListener(){}
how can i achieve what i wanted???
package com.Android.barcode;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class BarcodeActivity extends Activity {
public static String upc;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IntentIntegrator.initiateScan(this);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case IntentIntegrator.REQUEST_CODE: {
if (resultCode != RESULT_CANCELED) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(
requestCode, resultCode, data);
if (scanResult != null) {
upc = scanResult.getContents();
Intent intent = new Intent(BarcodeActivity.this, BarcodeResult.class);
startActivity(intent);
// put whatever you want to do with the code here
/* TextView tv = new TextView(this);
tv.setText(upc);
setContentView(tv);*/
}
}
break;
}
}
}
}
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
public Context call mcontext;<br> // ..... <br> Intent intent = new Intent(call mcontext, AboutActivity. class);<br> call mcontext. startActivity(intent);
The onStop() and onDestroy() methods get called, and Android destroys the activity.
Activity instances are always created by the Android system. This is because a lot of initializations have to be done for the activity to work. To create a new activity you call startActivity with an Intent describing the activity to start.
Since you don't want to create that dialog from that activity : You have two options
1) Call an Intent back to the activity you want the user to go to.
Intent intent = new Intent(getBaseContext(), theActivity.class);
getApplication().startActivity(intent) ;
or Else
2) Create a constructor for that class consisting of the dialog.
public class ABC {
Context iContext=null;
public ABC(Context con){
iContext=con;
}
....
}
Call the class with the Context of the activity. Like ABC(Cont)
.And then use ((Activity)iContext).finish()
within that class to finish that activity as you wish.
if Your class having constructor which having Context assign in it than u can Use this way
AlertDialog.Builder adb=new AlertDialog.Builder(context);
adb.setTitle("Are You Sure Want To Delete?");
adb.setPositiveButton("OK", new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}});
adb.setNegativeButton("CANCEL", new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
((Activity) context).finish();
}});
adb.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With