对不起我的不解,但我是android开发的新手.
我有一个活动A和活动B的应用程序,我从活动A转到活动B.当我离开活动A时,onSaveInstanceState方法被调用,但是当我回到活动A时(来自活动B在同一个应用程序中) ),onCreate方法中的bundle 为null.
我该怎么办,以保存活动A以前的状态?我只想存储应用程序生命周期的数据.
有人可以帮我弄这个吗?
这是我的活动A的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null)
{
Log.v("Main", savedInstanceState.getString("test"));
}
else
{
Log.v("Main", "old instance");
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState)
{
Log.v("Main", "save instance");
savedInstanceState.putString("test", "my test string");
super.onSaveInstanceState(savedInstanceState);
}
public void buttonClick(View view)
{
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
这是我的活动B的代码,当我按下按钮返回活动A:
public void onBack(View view)
{
NavUtils.navigateUpFromSameTask(this);
}
Run Code Online (Sandbox Code Playgroud) android android-lifecycle onrestoreinstancestate onsaveinstancestate
在我的 Android 应用程序中,我想使用 https 连接到使用自签名证书的用户指定服务器。因为https服务器是用户指定的,所以我之前不知道服务器的证书,因此我想:
我不想在用户不检查证书的情况下简单地接受每个自签名证书
我在第一步中遇到了困难,有人可以向我展示一个带有基本说明的工作示例吗?任何提示表示赞赏。多谢
我正在Android上实现本地通知,我遇到的问题是它们没有出现在Android 6.0(三星S7)上.我正在寻找解决方案,但我找不到任何解决这个问题的方法.我在正确的res/drawable文件夹中有图标,我也定义了通知标题,文本,铃声(原始文件夹)但它没有显示...有我的代码:
Context acontext = getApplicationContext();
PackageManager pm = acontext.getPackageManager();
Intent notificationIntent = pm.getLaunchIntentForPackage(acontext.getPackageName());
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(acontext, 0, notificationIntent, 0);
int notification_icon = acontext.getResources().getIdentifier("icon", "drawable", acontext.getPackageName());
int notificationID = 0;
// Build notification
Notification noti = new Notification.Builder(acontext)
.setContentTitle("Title")
.setContentText("Incoming text")
.setSmallIcon(notification_icon)
.setContentIntent(pendingIntent)
.setLights(Color.RED, 1, 1)
.build();
NotificationManager notificationManager = (NotificationManager) acontext.getSystemService(Context.NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.sound = Uri.parse("android.resource://" + acontext.getPackageName() + "/raw/incoming");
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notificationID, noti);
Run Code Online (Sandbox Code Playgroud)
有没有其他人遇到过这个问题?任何帮助,将不胜感激.谢谢.
notifications android android-notifications android-6.0-marshmallow
我使用以下代码来创建AlertDialog
CharSequence[] array = {"Font1", "Font2", "Font3", "Font4"};
callback = (DialogClickListener) fragment;
builder = new AlertDialog.Builder(context);
builder.setTitle("Font Settings")
.setSingleChoiceItems(array, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
selected = array[arg1].toString();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
callback.onYesClick(selected);
}
});
Run Code Online (Sandbox Code Playgroud)
如何设置默认选择的元素?请帮忙 :)
我想在RUNTIME更改我的按钮背景
我知道如何为按钮添加自定义背景,但是
如何将其更改为borderlessButtonStyle?在xml很简单,我用过:
style="?android:attr/borderlessButtonStyle")
Run Code Online (Sandbox Code Playgroud)如何切换回默认背景?以下不是我想要的(显然它不是Jelly Bean中使用的默认值)
changeableButton.setBackgroundResource(android.R.drawable.btn_default);
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助