我有App A和App B.在App中我想向App B发送广播.这是App A的代码:
final Intent intent = new Intent();
intent.setAction("com.pkg.perform.Ruby");
intent.putExtra("KeyName", "code1id");
intent.setComponent(new ComponentName("com.pkg.AppB", "com.pkg.AppB.MainActivity"));
sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)
在App B - In中MainActivity,我有MyBroadCastReceiverClass.
public class MainActivity extends Activity {
private MyBroadcastReceiver MyReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Receive broadcast from External App
IntentFilter intentFilter = new IntentFilter("com.pkg.perform.Ruby");
MyReceiver = new MyBroadcastReceiver();
if(intentFilter != null)
{
registerReceiver(MyReceiver, intentFilter);
}
}
public class MyBroadcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) { …Run Code Online (Sandbox Code Playgroud) 我想使用扩展BackupAgentHelper的MyBackUpAgent类在Android中备份数据.我正在使用SharedPreferences来存储数据.
我的主要活动代码是:
public class MainActivity extends Activity {
EditText inputtext;
TextView outputtext;
Button submit;
public static SharedPreferences sharedprefs;
static final String File_Name_Of_Prefrences ="godplay_preferences";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
init();
sharedprefs=getSharedPreferences(File_Name_Of_Prefrences,MODE_PRIVATE);
System.out.println("value="+sharedprefs.getString("Input",""));
outputtext.setText(sharedprefs.getString("Input",""));
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
populateUI();
}
});
}
public void populateUI()
{
String savedinput=inputtext.getText().toString();
System.out.println("savedinput="+savedinput);
outputtext.setText(savedinput);
sharedprefs=getSharedPreferences(File_Name_Of_Prefrences,MODE_PRIVATE);
Editor editor=sharedprefs.edit();
editor.putString("Input",inputtext.getText().toString());
editor.commit();
requestBackup();
}
private void init() throws ClassCastException
{
inputtext=(EditText) findViewById(R.id.edtInputText);
outputtext=(TextView) findViewById(R.id.txtOutputText);
submit=(Button) findViewById(R.id.btnSubmit); …Run Code Online (Sandbox Code Playgroud) 我有一个ImageView.当您单击ImageView时,它将打开图库,您将获取图像并在ImageView上显示它.我有一个条件,当我关闭我的应用程序,然后我打开它,图像将保留在那里.所以,为此,我将图像Uri存储在sharedprefrence上.在打开应用程序时,我正在检索相同的Uri并尝试在imageView上显示图像.
然而在一些手机中 - 图像看起来像Mi(Lollipop),三星(KitKat)一样完美,但它并没有出现在像摩托罗拉(Marshmallow),One Plus One(Marshmallow)这样的手机中.知道为什么会这样吗?这是我的代码
拿起我正在使用的图像
Intent intent=new Intent();intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), Constants.SELECT_PICTURE);
Run Code Online (Sandbox Code Playgroud)
在OnActivityResult()代码上
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==Constants.SELECT_PICTURE && resultCode==RESULT_OK && null!=data) {
Uri uri=data.getData();
Picasso.with(UsersProfileActivity.this)
.load(uri)
.centerCrop()
.resize(200,200)
.into(img_photo);
// This profile image i am storing into a sharedpreference
profile_image=uri.toString();
}
Run Code Online (Sandbox Code Playgroud)
在从sharedprefrence检索时,我通过使用将String转换为uri Uri.parse(profile_image)
但是如果我注意到,uri为不同的Android手机返回如下
Mi(Lollipop)- Uri=content://media/external/images/media/12415
samsung(KitKat)-Uri=content://media/external/images/media/786
Motorola(Marshmallow)- Uri=content://com.android.providers.media.documents/document/image%3A30731
One Plus One (Marshmallow)- Uri=content://com.android.providers.media.documents/document/image%3A475
Run Code Online (Sandbox Code Playgroud)
因此,当uri内容是-content:// media/external/images/media /是在ImageView Perfect上显示图像时,在其他情况下它不是
我正在尝试将listview项目制成带有圆角的矩形形状,但是我发生了什么,只有第一行在上部带有圆角,其余的子列表视图项目都是矩形,没有圆角.我不知道为什么会这样.
这是我的listview代码:
<ListView
android:id="@+id/listViewdoctorwithappointment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="10dp"
android:minHeight="80dp"
android:background="@drawable/customshapeduplicate"
android:cacheColorHint="@android:color/transparent"
android:divider="#4F94CD"
android:dividerHeight="10dp"
android:smoothScrollbar="true"
android:listSelector="@drawable/selector"
android:scrollbars="none" >
</ListView>
Run Code Online (Sandbox Code Playgroud)
这是我的customshapeduplicatefile是这样的:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#ffffff" android:endColor="#ffffff"
android:angle="270"/>
<corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
这是图像:

我有一个自定义列表视图,每行包含一个复选框和文本.现在我想要的是如果任何一个listview行的复选框被选中,那么其他行中的其他复选框如果被选中.it将被自动选择.(即一次只能选择一个复选框).我应该这样做.
到目前为止,我所做的工作如下:
public class CustomAdapter extends BaseAdapter{
Context context;
List<String> items;
boolean array[];
public CustomAdapter(Context context, List<String> items) {
super();
this.context = context;
this.items = items;
array =new boolean[items.size()];
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return items.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return items.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) …Run Code Online (Sandbox Code Playgroud) 我有3项活动.活动A,活动B,活动C.这是流程A-> B-> C. 现在我想从C.(即C-> A)来到活动A,而没有得到活动A的onCreate().
到目前为止,我的代码是:但它将调用ActivityA的onCreate().我想调用Restart().
Intent intent=new Intent(ActivityC.this,ActivityA.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
Run Code Online (Sandbox Code Playgroud)