我可以在Web开发中将变量设置为类似会话的上下文吗?
这是我的代码,我在Android应用程序启动时立即开发一个确认框:
package com.example.alertboxandloadingwidgets;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Boolean result = showConfirmationBox("Are you sure you want to do this",
this);
}
public Boolean showConfirmationBox(String messageToShow, final Context context) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
// set the message to display
alertbox.setMessage(messageToShow);
// set a positive/yes button and create a listener
alertbox.setPositiveButton("Yes", …Run Code Online (Sandbox Code Playgroud)