有没有办法检查在启动活动时是否已经通过了额外的活动?
我想做一些像(在onCreate()活动中):
Bundle extras = getIntent().getExtras();
String extraStr = extras.getString("extra");
if (extraStr == null) {
extraStr = "extra not set";
}
Run Code Online (Sandbox Code Playgroud)
但这是扔了一个java.lang.NullPointerException.
谢谢.
我在sharedUserID中感到困惑.什么是使用sharedUserId?如何使用?在android中使用哪里?
我正在尝试使用新的通知界面.我已经为通知添加了3个按钮,并且我想在点击每个按钮后将其保存到我的数据库中.
通知本身运行良好,并在调用时显示,我只是不知道如何捕获三个不同的按钮单击中的每一个.
我用a BroadcastReceiver来捕捉点击,但我不知道如何判断点击了哪个按钮.
这是代码AddAction(我已经排除了通知的其余部分,因为它运作良好) -
//Yes intent
Intent yesReceive = new Intent();
yesReceive.setAction(CUSTOM_INTENT);
Bundle yesBundle = new Bundle();
yesBundle.putInt("userAnswer", 1);//This is the value I want to pass
yesReceive.putExtras(yesBundle);
PendingIntent pendingIntentYes = PendingIntent.getBroadcast(this, 12345, yesReceive, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.addAction(R.drawable.calendar_v, "Yes", pendingIntentYes);
//Maybe intent
Intent maybeReceive = new Intent();
maybeReceive.setAction(CUSTOM_INTENT);
Bundle maybeBundle = new Bundle();
maybeBundle.putInt("userAnswer", 3);//This is the value I want to pass
maybeReceive.putExtras(maybeBundle);
PendingIntent pendingIntentMaybe = PendingIntent.getBroadcast(this, 12345, maybeReceive, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.addAction(R.drawable.calendar_question, "Partly", pendingIntentMaybe);
//No intent
Intent noReceive = …Run Code Online (Sandbox Code Playgroud) notifications android broadcastreceiver android-intent android-4.0-ice-cream-sandwich
使用android我意识到隐含意图在大多数情况下是很好的选择,因为它们具有灵活性.但是什么是显性意图呢?使用它们有什么好处?什么是常见的情况,使用它们是一个好习惯?
android android-intent android-implicit-intent explicit-intent
我有一个搜索屏幕,可以通过点击另一个屏幕的"名称"字段启动.
如果用户遵循此工作流程,我会在Intent的Extras中添加一个名为"search"的额外内容.此额外使用填充"name"字段的文本作为其值.创建搜索屏幕时,该额外用作搜索参数,并为用户自动启动搜索.
但是,由于Android会在屏幕旋转时销毁并重新创建活动,因此旋转手机会再次导致自动搜索.因此,我想在执行初始搜索时从Activity的Intent中删除"搜索"额外内容.
我试过这样做:
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey("search")) {
mFilter.setText(extras.getString("search"));
launchSearchThread(true);
extras.remove("search");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.如果我再次旋转屏幕,活动的意图的额外内容中仍然存在额外的"搜索".
有任何想法吗?
在我的应用程序中,我需要阅读Qr代码.我在网上搜索并找到了Zing代码但是很多开发人员使用它时遇到了问题,而且它似乎有问题!
如果我假设我的客户在他们的设备上安装了qr阅读器,我如何使用这些应用程序并通过隐式意图调用它们?
如果用户没有任何qr阅读器,应用程序会发生什么?如果它崩溃,我可以要求用户下载例如QrDroid,然后使用它吗?
我正在使用Make Sense of Multitouch中的代码示例
来缩放图像视图.在ScaleListener上,我添加ScaleGestureDetector.getFocusX() and getFocusY()内容以缩放手势的焦点.它工作正常.
问题是,在第一次多点触控时,整个图像绘制位置将变为当前触摸点并从那里进行缩放.你能帮我解决这个问题吗?
这是TouchImageView的My Code Sample.
public class TouchImageViewSample extends ImageView {
private Paint borderPaint = null;
private Paint backgroundPaint = null;
private float mPosX = 0f;
private float mPosY = 0f;
private float mLastTouchX;
private float mLastTouchY;
private static final int INVALID_POINTER_ID = -1;
private static final String LOG_TAG = "TouchImageView";
// The ‘active pointer’ is the one currently moving our object.
private int mActivePointerId = INVALID_POINTER_ID;
public TouchImageViewSample(Context context) …Run Code Online (Sandbox Code Playgroud) 我想检查一下用户是否在Google Play上评了我的应用,而不是有多少星,只要他们有.如果他们没有,我会通过一个对话框提示他们用这个代码给它评分:
startActivity( new Intent( Intent.ACTION_VIEW,
Uri.parse("market://details?id=packagename") ) );
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中我使用IntentService发送短信.
@Override
protected void onHandleIntent(Intent intent) {
Bundle data = intent.getExtras();
String[] recipients = null;
String message = getString(R.string.unknown_event);
String name = getString(R.string.app_name);
if (data != null && data.containsKey(Constants.Services.RECIPIENTS)) {
recipients = data.getStringArray(Constants.Services.RECIPIENTS);
name = data.getString(Constants.Services.NAME);
message = data.getString(Constants.Services.MESSAGE);
for (int i = 0; i < recipients.length; i++) {
if(!StringUtils.isNullOrEmpty(recipients[i])) {
try {
Intent sendIntent = new Intent(this, SMSReceiver.class);
sendIntent.setAction(Constants.SMS.SEND_ACTION);
PendingIntent sendPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, sendIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent deliveryIntent = new Intent(this, SMSReceiver.class);
deliveryIntent.setAction(Constants.SMS.DELIVERED_ACTION);
PendingIntent deliveryPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, deliveryIntent, …Run Code Online (Sandbox Code Playgroud) 我有一个工作的平板电脑应用程序,我现在也试图在手机上工作.在表格上,屏幕上有两个片段,一个列表片段和一个细节片段.当在电话上时,列表片段出现并在按下列表项时创建新活动.此活动只是在onCreate()方法中创建片段并将其提交到屏幕,如下所示.
// Place an DeallDetailsFragment as our content pane
DealDetailsFragment f = new DealDetailsFragment();
getFragmentManager().beginTransaction().add(android.R.id.content, f).commit();
getFragmentManager().executePendingTransactions();
Run Code Online (Sandbox Code Playgroud)
这是按预期工作的,但是从这个活动中我需要告诉片段要加载和显示的细节.在我的DealDetailsFragment类中,我有一个updateDeal()更新内容的方法,如下所示.
if (deal==null) { // could be null if user presses the loading deals list item before it loads
return;
}
this.deal=deal;
if (dealTitle==null) { // get the view objects only once
holder = new ViewHolder();
holder.dealHeat=(TextView) getView().findViewById(R.id.dealDetails_heat_textView);
holder.dealPrice=(TextView) getView().findViewById(R.id.dealDetails_price_textView);
holder.dealRetailer=(TextView) getView().findViewById(R.id.dealDetails_retailer_textView);
holder.dealTitle=(TextView) getView().findViewById(R.id.dealDetails_title_textView);
holder.dealDesc=(TextView) getView().findViewById(R.id.dealDetails_desc_textView);
holder.goToButton= (LinearLayout) getView().findViewById(R.id.dealDetails_goToDeal);
holder.dealImage=(ImageView) getView().findViewById(R.id.dealDetails_imageView);
holder.postedBy=(TextView) getView().findViewById(R.id.dealDetails_poster_textView);
holder.datePosted=(TextView) getView().findViewById(R.id.dealDetails_date_textView);
Run Code Online (Sandbox Code Playgroud)
getView() 当应用程序在只显示单个片段的手机上运行时返回null.
有任何想法吗?不幸的是,网上没有很多片段示例.
android android-intent android-layout android-fragments android-4.0-ice-cream-sandwich
android ×10
android-intent ×10
android-4.0-ice-cream-sandwich ×2
android-ndk ×1
bundle ×1
google-play ×1
handler ×1
implicit ×1
java ×1
qr-code ×1
rating ×1
service ×1