i'm a beginner in Android
and i'm trying different programs but this error still show up
':app:processDebugManifest' Manifest merger failed with multiple errors
how i can fix it
this is my code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.nhn.test">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:icon,android:theme"
>
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="Main2Activity"
android:label="#string/title_activity_main2"
android:theme="#style/AppTheme.NoActionBar" >
</activity>
<activity android:name=".Main2Activity" >
</activity>
</application>
<android:replace>"android:icon"</android:replace>
</manifest>
this is the first layout
package com.example.nhn.test;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
public void BtnNex(View view){
Intent int1= new Intent(this,Main2Activity.class);
startActivity(int1);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
this is the second had one button
package com.example.nhn.test;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class Main2Activity extends AppCompatActivity {
public void BtnPrev(View view){
Intent int2= new Intent(this,MainActivity.class);
startActivity(int2);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}
Related
I am building 2 NFC enabled apps, one is supposed to send a message and the other to receive it.
Sending app Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joyride.nfc_merchant">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.NFC_Merchant">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Sending app Main Activity
package com.joyride.nfc_merchant;
import androidx.appcompat.app.AppCompatActivity;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
String message;
NdefRecord ndefRecord;
NdefMessage ndefMessage;
NfcAdapter nfcAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
}
public void sendMessage(View view) {
message = ((EditText) findViewById(R.id.text_message)).getText().toString();
ndefRecord = NdefRecord.createTextRecord(null, message);
ndefMessage = new NdefMessage(ndefRecord);
nfcAdapter.setNdefPushMessage(ndefMessage, this);
}
}
Receiving app android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joyride.nfc_customer">
<uses-permission android:name="android.permission.NFC" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.NFC_Customer">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Receiving app Main Activity
package com.joyride.nfc_customer;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Parcelable;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
TextView messageView = (TextView)findViewById(R.id.messageView);
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
Parcelable[] rawMessages =
intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if (rawMessages != null) {
NdefMessage[] messages = new NdefMessage[rawMessages.length];
for (int i = 0; i < rawMessages.length; i++) {
messageView.setText(((NdefMessage) rawMessages[i]).toString());
}
}
}
}
}
I've installed each app on another phone. Off course the receiving app is not registering the message. Am I missing something here? How do I go about debugging this?
How do you add an activity (SplashActivity.java in my case) that launches automatically before the MainActivity? I've added in the below code but the activity is still being skipped over. I've already tried going to Edit Configurations -> Launch -> Default Activity. And the Splash Activity is the only activity with an intent filter.
SplashActivity.java
package com.example.simplesplashscreen;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.widget.AppCompatImageView;
public class SplashActivity extends Activity implements InterfaceSplash {
private AppCompatImageView image;
private AnimatedVectorDrawable animation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
image = (AppCompatImageView) findViewById(R.id.splashobject);
launchSplashScreen();
dismissSplashScreen();
}
#Override
public void launchSplashScreen() {
super.onStart();
Drawable d = image.getDrawable();
if (d instanceof AnimatedVectorDrawable) {
Log.d("testanim", "onCreate: instancefound" + d.toString());
animation = (AnimatedVectorDrawable) d;
animation.start();
}
}
#Override
public void dismissSplashScreen() {
// Start Main Activity
startActivity(new Intent(SplashActivity.this,MainActivity.class));
finish();
}
}
AndroidManifest.java
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.simplesplashscreen">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.SimpleSplashScreen">
<activity
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
</activity>
<activity
android:name=".SecondActivity"
android:exported="true">
</activity>
</application>
</manifest>
My Android Studio version is 1.5.1
I have created an XML and it can show well in the AndroidStudio,
but when i run it in genymotion or my phone,it can not show the layout.
I am annoyed at this.I do not know what is wrong.
hope someone could help me.
code image
code:
SplashActivity
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class SplashActivity extends AppCompatActivity {
private Button mEnterButton;
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.enter_button:
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
break;
}
}
};
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_splash);
mEnterButton = (Button) findViewById(R.id.enter_button);
mEnterButton.setOnClickListener(mOnClickListener);
}
}
MainActivity
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button_first).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,SplashActivity.class);
startActivity(intent);
}
});
}
}
avtivity_splash_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#color/splashBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/splash_tv_text"
android:textSize="28sp"
android:id="#+id/text_splash"
android:textColor="#color/white"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/splash_click_to_inter"
android:id="#+id/enter_button"/>
</LinearLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.geekband.geekbandprojects">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
</activity>
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Why you need a PersistableBundle ?
make your OnCreateMethod like:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//anything here
}
i'm considering that you haven't already set the SplashActivity as the startup activity.So add the following code(or change it) on Manifest:
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
And let us know your MainActivity code and of course your Manifest with the logcat.
I will updated my answer after that.
And of course, i think you should use onClick on Oncreate method.
I have created 2 activities.When i call second activity from first via intent then onCreate method of second activity does not called.Although first activity's onCreate method is called normally as it should be.
Below is the code for first activity.
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
int counter;
Button add, sub;
TextView tView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
tView = (TextView) findViewById(R.id.textView1);
// Intent in = new Intent(AC);
add.setOnClickListener(this);
sub.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bAdd:
tView.setText(++counter + "");
try {
Intent nextIntentView = new Intent(MainActivity.this, ShowValueActivity.class);
nextIntentView.putExtra("key", "counter");
startActivity(nextIntentView);
}
catch (Exception e) {
e.printStackTrace();
}
break;
case R.id.bSub:
tView.setText(--counter + "");
break;
default:
break;
}
}
}
Code for second activity.
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ShowValue extends Activity {
TextView tv_showValue1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_value);
tv_showValue1 = (TextView) findViewById(R.id.tv_showValue);
Intent gotIntent = (Intent) this.getIntent();
Bundle gotBundle = gotIntent.getExtras();
tv_showValue1.setText(gotBundle.getString("key"));
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webesperto.webespertofirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.webesperto.webespertofirstapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShowValueActivity"
android:label="#string/title_activity_show_value" >
</activity>
</application>
</manifest>
you have
<activity
android:name=".ShowValueActivity"
android:label="#string/title_activity_show_value" >
</activity>
instead of
<activity
android:name=".ShowValue"
android:label="#string/title_activity_show_value" >
</activity>
Since your code reads
public class ShowValue extends Activity {
Though, why doesnt your application crash saying NoActivityFoundException ??
please have a look on manifest
change
<activity
android:name=".ShowValueActivity"
android:label="#string/title_activity_show_value" >
</activity>
to
<activity
android:name=".ShowValue"
android:label="#string/title_activity_show_value" >
</activity>
yours manifest should be like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webesperto.webespertofirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.webesperto.webespertofirstapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShowValue"
android:label="#string/title_activity_show_value" >
</activity>
</application>
</manifest>
Change your Second Activity name in class file like this:
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ShowValueActivity extends Activity {
TextView tv_showValue1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_value);
tv_showValue1 = (TextView) findViewById(R.id.tv_showValue);
Intent gotIntent = (Intent) this.getIntent();
Bundle gotBundle = gotIntent.getExtras();
tv_showValue1.setText(gotBundle.getString("key"));
}
}
It will work:)
I try to write app which can start when usb connect
I learn from Starting my android application automatically after connecting the USB cable.
my code is
package com.example.formatsdcard;
import java.io.File;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MainActivity extends Activity {
public class OnPowerReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button mButton01 = (Button)findViewById(R.id.button1);
mButton01.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
wipeMemoryCard();
}
});
MY Manifest is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.formatsdcard"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.formatsdcard.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".OnPowerReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
</intent-filter>
</receiver>
</application>
my app can run after I click it but it will show there're some problem try again later when I connect my usb cable.
How should I change my code to let it work normally.
You should probably try
<receiver android:name="MainActivity$OnPowerReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
</intent-filter>
</receiver>
Or try putting OnPowerReceiver as a public class in your package com.example.formatsdcard
Create a own class for your onPowerReceiver. Don't put it in your MainActivity.