All,
I seem to have an issue that should be fairly easy for you guys to
figure out. I'm using an alertdialog to present the user with 4
options to create shortcuts on the launcher main screen. The problem
I'm running into is when I select the shortcut I want the dialog goes
away, and the shortcut is not created until I hit the back button. So
something is either failing to finish or it's waiting. My code is
below. If anyone could help that would be awesome.
package com.skittles.widget;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.widget.TextView;
import com.raue.rebootwidget.R;
public class LauncherShortcuts1 extends Activity {
private static final String EXTRA_KEY =
"com.example.android.apis.app.LauncherShortcuts";
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Resolve the intent
final Intent intent = getIntent();
final String action = intent.getAction();
// If the intent is a request to create a shortcut, we'll do
that and exit
String[] items={"Shortcut1",
"Shortcut2","Shortcut3","Shortcut4"};
new AlertDialog.Builder(LauncherShortcuts1.this)
.setCancelable(false)
.setTitle("Select Shortcut")
.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 1) {
if
(Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
setupShortcut();
finish();
return;
}
}
}})
.show();
setContentView(R.layout.configure);
TextView intentInfo = (TextView)
findViewById(R.id.button_two);
String info = intent.toString();
String extra = intent.getStringExtra(EXTRA_KEY);
if (extra != null) {
info = info + " " + extra;
}
intentInfo.setText(info);
}
private void setupShortcut() {
// First, set up the shortcut intent. For this example, we
simply create an intent that
// will bring us directly back to this activity. A more
typical implementation would use a
// data Uri in order to display a more specific result, or a
custom action in order to
// launch a specific operation.
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(this,
PoweroffActivity.class.getName());
shortcutIntent.putExtra(EXTRA_KEY, "ApiDemos Provided This
Shortcut");
// Then, set up the container intent (the response to the
caller)
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.shortcut1));
Parcelable iconResource =
Intent.ShortcutIconResource.fromContext(this, R.drawable.shortcut);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
iconResource);
// Now, return the result to the launcher
setResult(RESULT_OK, intent);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en