Android can't launch activity - android

So i have this activity :
public class settings_dock extends Activity {
AlertDialog alert;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.settings);
//Weather settings
ListView listView = (ListView) findViewById(R.id.settings);
String[] values = new String[] { "Enable/Disable","Configure Item 1","Configure Item 2","Configure Item 3","Configure Item 4"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
// Assign adapter to ListView
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(position == 0)
{
final CharSequence[] items = {"Enabled", "Disabled"};
AlertDialog.Builder builder = new AlertDialog.Builder(settings_dock.this);
builder.setTitle("The Dock is ....");
SharedPreferences dock = app.getContext().getSharedPreferences("dock",app.getContext().MODE_WORLD_READABLE);
builder.setSingleChoiceItems(items,dock.getInt("enabled_disabled",-1), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
SharedPreferences dock = app.getContext().getSharedPreferences("dock",app.getContext().MODE_WORLD_READABLE);
SharedPreferences.Editor prefsEditor = dock.edit();
prefsEditor.putInt("enabled_disabled",item);
prefsEditor.commit();
alert.dismiss();
if(item == 0)
{
}
if(item == 1)
{
}
}
});
alert = builder.create();
alert.show();
}
if(position == 1)
{
Intent in=new Intent(settings_dock.this,set_dock.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.putExtra("dock_location",1);
}
if(position == 2)
{
Intent in=new Intent(settings_dock.this,set_dock.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.putExtra("dock_location",2);
}
if(position == 3)
{
Intent in=new Intent(settings_dock.this,set_dock.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.putExtra("dock_location",3);
}
if(position == 4)
{
Intent in=new Intent(settings_dock.this,set_dock.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.putExtra("dock_location",4);
}
}
});
}
}
and I am trying to launch a intent as you can see
but simplay nothing happens not even a error in logcat
The intent to launch is lusted in my manifest
I am realy puzzeld right now :(
m
edit :
manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.alexander.fuchs.lockscreen"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".app"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:excludeFromRecents="true"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="boot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<service
android:name="lockservice"
android:process=":lockscreen"
android:icon="#drawable/ic_launcher"
android:label="Lockscreen">
</service>
<activity
android:name=".weather_update"
android:theme="#android:style/Theme.Translucent">
</activity>
<activity
android:name=".restart_service"
android:theme="#android:style/Theme.Translucent">
</activity>
<activity
android:name=".settings">
</activity>
<activity
android:name=".settings_weather">
</activity>
<activity
android:name=".settings_general">
</activity>
<activity
android:name=".settings_dock">
</activity>
<activity
android:name=".settings_personalisation">
</activity>
<activity
android:name=".set_dock"
android:theme="#android:style/Theme.Dialog"
android:screenOrientation="portrait">
</activity>
</application>
</manifest>

You haven't called:
startActivity(in);
Hopefully this helps.

Try adding startActivity(in) in each of the if statement. To start an activity you need to call startActivity(intent) method.

Related

Failed to send sms in Android Studio

New to android and I can't seem to be able to send any text to myself on my emulator. I have allowed permission in the manifest file and imported the necessary classes but still can't seem to figure out what's wrong. Any help would be greatly appreciated.
public class Detail extends AppCompatActivity {
public Button button5;
Spinner spinner2;
ArrayAdapter<CharSequence> adapter;
EditText editText4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
editText4 = (EditText) this.findViewById(R.id.editText4);
button5 = (Button) findViewById(R.id.button5);
button5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String contact = editText4.getText().toString();
String message = "Help is on the way.";
sendMessage(contact,message);
Intent b = new Intent(Detail.this, End.class);
startActivity(b);
}
});
spinner2 = (Spinner) findViewById(R.id.spinner2);
adapter = ArrayAdapter.createFromResource(this,R.array.selectissue,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter);
spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getBaseContext(),parent.getItemAtPosition(position) + " selected" , Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
private void sendMessage(String contact, String message)
{
SmsManager smsManager = SmsManager.getDefault();
try {
smsManager.sendTextMessage(contact, null , message , null , null);
Toast.makeText(getApplicationContext(), "SMS Sent.", Toast.LENGTH_LONG).show();
} catch (Exception e)
{
Toast.makeText(getApplicationContext(), "SMS failed to send.", Toast.LENGTH_LONG).show();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_detail, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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=".Login"
android:label="#string/title_activity_login" >
</activity>
<activity
android:name=".Option"
android:label="#string/title_activity_option" >
</activity>
<activity
android:name=".Detail"
android:label="#string/title_activity_detail" >
</activity>
<activity
android:name=".End"
android:label="#string/title_activity_end" >
</activity>
<activity
android:name=".Feedback"
android:label="#string/title_activity_feedback" >
</activity>
<activity
android:name=".Student"
android:label="#string/title_activity_student" >
</activity>
<activity
android:name=".Incident"
android:label="#string/title_activity_incident" >
</activity>
<activity
android:name=".Help"
android:label="#string/title_activity_help" >
</activity>
<activity
android:name=".Wifi"
android:label="#string/title_activity_wifi" >
</activity>
<activity
android:name=".Basic"
android:label="#string/title_activity_basic" >
</activity>
<activity
android:name=".Home"
android:label="#string/title_activity_home" >
</activity>
<activity
android:name=".Guide"
android:label="#string/title_activity_guide" >
</activity>
<activity
android:name=".VPN"
android:label="#string/title_activity_vpn" >
</activity>
<activity
android:name=".VDI"
android:label="#string/title_activity_vdi" >
</activity>
<activity
android:name=".Location"
android:label="#string/title_activity_location" >
</activity>
<activity
android:name=".Phone"
android:label="#string/title_activity_phone" >
</activity>
<activity
android:name=".config"
android:label="#string/title_activity_config" >
</activity>
<activity
android:name=".Script"
android:label="#string/title_activity_script" >
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name="com.facebook.FacebookActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider"
android:exported="true" />
<activity
android:name=".Register"
android:label="#string/title_activity_register" >
</activity>
<activity
android:name=".Signup"
android:label="#string/title_activity_signup" >
</activity>
</application>
You can not send text messages via emulator if you want to test SMS feature then test it on real android device with activated sim card.

app unfortunately stopped when use "Intent intent = new ...." method to change screen

I have created a simple app.
one screen of my app has following code and I use a Button (id "sendManual") to change the app view to another one.
please look at the end of this code, you can seen the button id "sendManual".
I have setup it to change screen view to App2Activity.java
(I have put the Code of App2Activity java below this code, then you can check it also)
I installed this app on my android phone, But when I click Button(id"sendManual") app suddenly Stopped and says
Unfortunately,XXXXX app has stopped
public class showPermission implements View.OnClickListener {
Dialog dialog;
Activity activity;
public void showDialog(final Activity activity){
dialog = new Dialog(activity);
dialog.setCancelable(false);
this.activity=activity;
dialog.setTitle("XXXXX");
dialog.setContentView(R.layout.permission);
Button Sendcancel = (Button) dialog.findViewById(R.id.sendCancel);
Button SendNow = (Button) dialog.findViewById(R.id.sendNow);
Button sendManual = (Button) dialog.findViewById(R.id.sendManual);
sendManual.setOnClickListener(this);
SendNow.setOnClickListener(this);
Sendcancel.setOnClickListener(this);
dialog.show();
}
#Override
public void onClick(View view) {
int id=view.getId();
if(id==R.id.sendCancel){
dialog.dismiss();
}
else if(id==R.id.sendNow){
sendSMS();
}
else if(id==R.id.sendManual){
Intent intent = new Intent(activity, App2Activity.class);
activity.startActivity(intent);
}
}
Here is the code of App2Activity.java
public class App2Activity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
findViewById(R.id.start).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sendSMS2();
}
});
}
............ etc
Here is manifest file.
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
</application>
You are not properly set context in Intent.Use this
Intent intent = new Intent(getApplicationContext(), App2Activity.class);
startActivity(intent);
instead of
Intent intent = new Intent(activity, App2Activity.class);
activity.startActivity(intent);
This all is happening because you didn't declare App2Activity in Manifest.xml. That is compulsory to declare all the activities in manifest file.
Replace your manifest.xml with this one:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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=".App2Activity"/>
</application>

Android: ActivityNotFoundException

I'm new to android and java programming and I'm getting ActivityNotFoundException in my app.
Here these are the only two times the activity is called:
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String selectedItem = (String) lvCheckLists.getItemAtPosition(position);
Intent i= new Intent("com.teamvdb.checklist.checkListActivity");
// Package name and activity
// Intent i= new Intent(MainActivity.this,SecondActivity.Class);
// Explicit intents
i.putExtra("selectedItem",selectedItem);
// Parameter 1 is the key
// Parameter 2 is your value
startActivity(i);
Intent openCheckListActivity = new ntent("com.teamvdb.checklist.checkListActivity");
startActivity(openCheckListActivity);
}
});
}
And here there is my Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.teamvdb.checklist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name=".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=".checkListActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
I have spent the last 20 minutes trying to figure out what is wrong with it but I can't see the problem.
And yes the class is spelled correctly.
Explicitly start checkListActivity :
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
String selectedItem = (String) lvCheckLists.getItemAtPosition(position);
Intent i= new Intent(MainActivity.this,checkListActivity.class);
i.putExtra("selectedItem",selectedItem);
startActivity(i);
});
intent-filter not required for checkListActivity so remove it and define as simple in AndroidManifest.xml :
<activity android:name=".checkListActivity"/>
Note : Remove unneccsary code which start checkListActivity again.

Android Widget And Listview

I'm trying to create a widget for my application . I want it to be like this :
The user selects my widget among all widgets then a listview appears the user selects on of the items and the widget in that category (which is introduced in the application) will show up
But when choosing the Widget "forceClose" happens . I attach my codes
Thanks for your help
public class WidgetConfig extends ListActivity implements OnItemClickListener {
AppWidgetManager awm;
Context c;
int awID;
public String LS [] = {"C", "B", "A"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.id.listviewfirstshow);
setListAdapter(new ArrayAdapter<String>(this,R.layout.widget_config , LS));
ListView lv = (ListView)findViewById(R.id.listviewfirstshow);
lv.setOnItemClickListener(this);
Intent i = getIntent();
Bundle extras = i.getExtras();
if (extras != null) {
awID = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
else {
finish ();
}
awm = AppWidgetManager.getInstance(c);
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
RemoteViews rv = new RemoteViews(c.getPackageName() R.layout.widget);
Intent in = new Intent(c, WidgetLearn2Activity.class);
PendingIntent pi = PendingIntent.getActivity(c, 0, in, 0);
rv.setOnClickPendingIntent(arg2, pi);
awm.updateAppWidget(awID, rv);
Intent result = new Intent();
result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID);
setResult(RESULT_OK, result);
finish();
}
}
and the manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="learn.widget" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" >
<activity android:name=".WidgetLearn2Activity" 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=".PointlessWidget" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="#xml/widget_stuff" />
</receiver>
<activity android:name=".WidgetConfig" android:label="#string/app_name">
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
</application>
</manifest>

Why different activities appear as separate application in android

I am creating a Jigsaw Puzzle application in android. I have created two activites, activity_jigsaw.xml and activity_level.xml. One activity is created by default (Displaying Hello World!) which I modified and created a new activity by following these steps:
File -> New -> Other -> Android Activity
But when I install the application these two files (and all other activities of the application) are installed as a separate project. But at the same time they are also interlinked. The Java code of the files as follows:
Jisaw.java file contains:
public class Jigsaw extends Activity {
Intent intent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jigsaw);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_jigsaw, menu);
return true;
}
public void play(View v)
{
try
{
intent = new Intent(this, Level.class);
startActivity(intent);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Here Play is a function which is called when an image is clicked.
Level.java file contains:
public class Level extends Activity {
Intent intent;
String level = "";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_level, menu);
return true;
}
public void easy(View v)
{
level = "easy";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
public void medium(View v)
{
level = "medium";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
public void hard(View v)
{
level = "hard";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
}
Functions easy, medium and hard are called when a corresponding image is clicked.
Can somebody please tell me that what I am doing wrong?
Thanks in advance..
Here is the manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maju.jigsawpuzzle"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Jigsaw"
android:label="#string/title_activity_jigsaw" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Level"
android:label="#string/title_activity_level" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Play"
android:label="#string/title_activity_play" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PlayBoard"
android:label="#string/title_activity_play_board" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You probably are defining android.intent.category.LAUNCHER intent category to all the activities in your AndroidManifest.xml, it creates an icon in the app launcher. Activities other than main should not have this intent filter.
Do something like this:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:name=".JigSaw" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Level" />
<activity android:name=".Play" />
<activity android:name=".Playboard" />
</application>
EDIT:
As you just posted, you are indeed doing that, just remove the intent filter from other activities.

Categories

Resources