I am working on widget project and when I touch the widget a new activity that is styled like a dialog box. The main activity opens and the dialog styled activity appears and when I touch the main activity the dialog styled activity disappears.
1) Is there a way to disable the activity? or
2) Is there away to open the dialog styled activity without opening the activity?
Here is my onReceive Class in my BroadcastReceiver
public void onReceive(Context context, Intent intent)
{
Log.i(TAG,"In onReceive");
if(intent.getAction().equals(INTENT_ACTION))
{
Intent mIntent = new Intent(context,sendActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mIntent);
}
}
Dialog Styled Actvity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp" />
<TextView
android:id="#+id/tvdialogTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:layout_toRightOf="#+id/image"/>
<TextView
android:id="#+id/tvStatus01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF" />
<TextView
android:id="#+id/tvStatus02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"/>
<Button
android:id="#+id/btnWidgetDialogCancel"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/image"
/>
</RelativeLayout>
Part of my Manifest
<activity
android:name="com.example.widget.sendActivity"
android:theme="#android:style/Theme.Dialog"
android:excludeFromRecents="true">
</activity>
Thanks in advance.
I used this line if anyone else is interested
this.setFinishOnTouchOutside(false);
Related
I am using a startActivityForResult method to get a string from an activity,the activity has an editview and a button to return the inputted value of the editview,but when i click on the button,it keeps telling me "Unfortunately,myapp has stopped",dont know where the problem is coming from?
This is the line calling the activity
startActivityForResult(new Intent("com.dreama.trafic.SearchActivity"),request_Code);
and this is the xml file for the activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editSearch"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:text="#string/searchLocation"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#f00" />
<EditText
android:id="#+id/editSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10" />
<Button
android:id="#+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:onClick="click"
android:text="#string/search" />
</RelativeLayout>
and this is the click method
public void click(View view) {
Intent data = new Intent();
EditText editSearch = (EditText) findViewById(R.id.editSearch);
data.setData(Uri.parse(editSearch.getText().toString()));
setResult(RESULT_OK, data);
finish();
}
Try this..
I guess you are getting ActivityNotFoundException
Change this..
startActivityForResult(new Intent("com.dreama.trafic.SearchActivity"),request_Code);
to
startActivityForResult(new Intent(currentActivity.this,SearchActivity.class),request_Code);
it also may be because you have not declared SearchActivity.java in your manifest file as
<activity android:name=".SearchActivity"/>
For an application I am designing we have to deal with some "special" needs of our users. One of these is to create a navigation sidebar that has to appear in almost all the activities.
This navigation bar has to contain always the same three buttons that links to three activities: HOME, INFO, CONFIGURATION.
Each of these three activities can also load others activities that can (or cannot) contain this navigation bar.
Each of these buttons has to reset the current activity-stack status bringing to the top the corresponding activity selected by the user.
The navigation bar has to be customisable (made visible/invisible) and I would like also to deactivate some of the buttons.
EDIT: It has to be similar to a Drawer, but the buttons have to be highly customisable (in size and appearance) and it has to be always on (no sliding functions).
What is the best way to achieve that without manually including those buttons in each of my layouts?
You can create this layout manually but only once - in your ActivityBase class. Other activities can extend this base class.
EDIT:
As I said, I'm improving my answer.
So my idea is to create an Activity with menu. And if other Activity needs to have the same menu it can extend this ActivityBase and add it's own layout.
Let's look on a simple example.
ActivityBase layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout
android:id="#+id/menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#android:color/black" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button1"
android:layout_centerHorizontal="true"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/menu" >
</RelativeLayout>
</RelativeLayout>
As you can see I created a simple layout that contains menu bar and a container for layout from Activities that will be extending AcivityBase.
Now ActivityBase:
public class ActivityBase extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);
}
}
It's a simple Activity, but if you want, you can also place here menu events handling if they are the same for all Activities that will be extending this.
And now let's see at SecondActivity's layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
It's a normal layout, nothing special. I put some controls in there just for purpose of this example.
And SecondActivity class:
public class SecondActivity extends MainActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = getLayoutInflater();
inflater.inflate(R.layout.second_activity, (ViewGroup) findViewById(R.id.container));
}
}
It extends ActivityBase and what is important - it does not call setContentView. Instead we are creating LayoutInflater and we are inflating second_activity layout in the container that we created in activity_base layout.
I am creating an android application in which i have a activity which contain several elements like Switch, TextView etc.
I need to get the values from all Switch elements whether it is checked or not.
it will be great if anyone show me the proper way to transfer multiple values to different activity for further calculation.
Thanks
here is my XML code:
<LinearLayout
android:id="#+id/configSwitchHldr"
android:layout_marginTop="10dp"
android:layout_span="2"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp" >
<TextView
android:text="#string/coreHardware"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:textColor="#color/green"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#363636" />
<Switch
android:id="#+id/switch1"
android:layout_width="fill_parent"
android:layout_height="14.5sp"
android:textOn="ON"
android:textOff="OFF"
android:text="CPU"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#363636" />
<Switch
android:id="#+id/switch2"
android:layout_width="fill_parent"
android:layout_height="14.5sp"
android:textOn="ON"
android:textOff="OFF"
android:text="Memory"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#363636" />
<Switch
android:id="#+id/switch3"
android:layout_width="fill_parent"
android:layout_height="14.5sp"
android:textOn="ON"
android:textOff="OFF"
android:text="Storage"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#363636" />
</LinearLayout>
Ok, so based on your comment this is how it could be done:
In your first Activity, you would need a method, that gathers all the switches states and pass them along to the next activity. Passing parameters along to other Activities can be achieved by putting them inside the Intent you send to open the new Activity.
The method for getting the Switches states and passing them to a new Activity would roughly look something like this:
Intent i = new Intent(MainActivity.this, NewActivity.class);
i.putExtra("switch1", switch1.isChecked());
i.putExtra("switch2", switch2.isChecked());
i.putExtra("switch3", switch3.isChecked());
startActivity(i);
Put this inside the onClickListener for a Button for instance like so:
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, NewActivity.class);
i.putExtra("switch1", switch1.isChecked());
i.putExtra("switch2", switch2.isChecked());
i.putExtra("switch3", switch3.isChecked());
startActivity(i);
}
});
Now when you click the Button you'll be sent to NewActivity.
To retrieve the parameters passed on from the MainActivity, you should do something like this in you onCreate method of the NewActivity:
boolean bool1 = getIntent().getExtras().getBoolean("switch1");
boolean bool2 = getIntent().getExtras().getBoolean("switch2");
boolean bool3 = getIntent().getExtras().getBoolean("switch3");
You could pass the variables on from MainActivity by putting them inside a boolean array, but that is overkill in my opinion.
Also take a look at this SO post: How do I pass data between Activities in Android application? - there's a lot of these.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="xyz" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
I have an XML layout as above and when I click that xyz button I want to launch my application "Sample App" which will show a dialog.
I have enabled "talkback" application from settings ->Accessibility.
Then once I click xyz button, talkback app is saying "alert.." but its not saying "alert + dialog title".
But if i start a dialog in my application then its saying the dialog title correctly.
Declare Your activity in manifest like..
<activity
android:name=".ActivityName"
android:theme="#android:style/Theme.Dialog" >
I'd like to provide a Button in the PreferenceActivity. The user should be able to set a
time (e.g. via TimePicker), but there's no ButtonPreference or something like that. I don't want to use EditTextPreference.
So do I have to use a default Button in the PreferenceActivity and save the settings for it manually?
Regards,
cody
Create a custom DialogPreference that incorporates a TimePicker widget. No button required. Should be under 100 lines of code.
Here is a sample project showing, among other things, a custom ColorPreference.
Create a different layout including your custom controls and include ListView on top, see the example below
// extra_settings.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView
android:id="#+id/feedback"
android:text="Feedback"
/>
<Button
android:id="#+id/about"
android:text="About"
/>
</LinearLayout>
Once this done, onCreate method of your class which is extended from PreferenceActivity add following line
setContentView(R.layout.settings_extras); //name of your layout
bind OnClickListener
View.OnClickListener feedbackPageRedirect = new View.OnClickListener()
{
public void onClick(View v)
{
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback ");
startActivity(emailIntent);
}
};
You can put the button in the activity_layout.xml . For example, if "Activity_Setup.java" is your setup activity, "activity_setup.xml" is its layout, and "myprefs.xml" is the file where your preference layout is stored, then
your should put the button in "activity_setup.xml" under the list, most preferable in a TableRow, like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/llprefs">
<ListView
android:id="#+id/android:list"
android:tag="lvprefs"
android:layout_width="match_parent"
android:layout_height="0.0dp"
android:layout_weight="1" >
</ListView>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
>
<Button
android:id="#+id/btRegister"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/IdonothaveA"
android:onClick="onClick"
/>
<Button
android:id="#+id/btForgot"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/Iforgot"
android:onClick="onClick" />
<!--
<Button
android:id="#+id/btContact"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/Contact"
android:onClick="onClick" />
-->
</TableRow>