How can I start a new activity from my android code? - android-activity

I am totally new to android and I have a question that I would thank a lot if somebody can answer me.How can I start a new activity from my android code? For example if in my current activity, string x1 = string x2, then I want to start new activity

Suppose your new Activity is called CoolActivity then you do the following to start your activity:
Intent intent = new Intent(this, CoolActivity.class);
startActivity(intent);
for your reference: http://developer.android.com/training/basics/firstapp/starting-activity.html

Do you want to create an other activity in your code?
Normally you only have one activity per view. If you want to start an other activity, you have to create an other file for exemple activity2.java
Add this activity in the manifest.xml like this:
<activity
android:name=".activity2"
android:screenOrientation="landscape" />
And in the beginning of your activity2.java, start with something like that:
public class Activity2 extends Activity{
I don't if i answered your question or not ...

Related

Changing name after refactoring an activity does not work

I have an intent
Intent(context, VisualCActivity::class.java).putExtra("Pox", BLBIndex)
thats works before.
Then I refactor the activity to another name and it works again ???
but the old name in the intent stays the same
But when I change the name of the activity in the intent to the new name
it does not work (unresolved reference)
What can I do?
Edit: I found the old activity name in the manifest
<activity
android:name=".VisualCActivity"
android:exported="false"
android:label="#string/title_activity_visual_cactivity"
android:theme="#style/Theme.LKPRG2023" />
Can I rename it here?
Android Studio shows in project window the new name
Found the mistake
class declaration name hasn't change - now it works
class FRMain : ComponentActivity() {

Use eclipse GMF to create read only diagram

I followed the file system example http://gmfsamples.tuxfamily.org/wiki/doku.php?id=gmf_tutorial1
what I wanted to do is not using the generated editor with its palette.
I created a new plugin with one view and I wanted to create a diagram programatically inside this view to show for instance 2 objects connected with link
I came across this answer GMF display diagram example
but it didn't help me a lot.
in createPartControl of my view I did
#Override
public void createPartControl(Composite parent) {
DiagramGraphicalViewer viewer = new DiagramGraphicalViewer();
viewer.createControl(parent);
RootEditPart root = EditPartService.getInstance().createRootEditPart(diagram);
viewer.setRootEditPart(root);
viewer.setEditPartFactory(new EcoreEditPartProvider());
viewer.getControl().setBackground(ColorConstants.listBackground);
viewer.setContents(diagram);
}
as in the answer but I didn't know how to get that "diagram" variable
The easiest would be use the same GraphicalViewer for your view and the same diagram as well. Just get your DiagramEditPart from the viewer and call disableEditMode() on it. (Do the appropriate type casting if necessary).

How to invoke a "loose Xaml"-defined activity from another "loose Xaml"-defined activity?

I have two "loose" XAML files, each declarativly defining composite activity which is composed of some custom (compiled) code-activities.
Now, I would like the activity defined in the 1st "loose" Xaml to 'contain' the activity defined in the 2nd "loose" Xaml as of its steps.
However, I have no clue how to 'glue' both activities together such that 1st activity will know to correctly load the activity from the 2nd Xaml.
So when calling:
XamlXmlReader xr = new XamlXmlReader(#"FirstLooseActivity.xaml");
ActivityBuilder ab = (ActivityBuilder)XamlServices.Load(ActivityXamlServices.CreateBuilderReader(xr));
I end up with a XamlObjectWriterException (after I loaded all relevant assemblies to my hosting app):
Cannot create unknown type '{clr-namespace:SecondLooseActivity}MyActivity
Since there is no Xlink support in MS, is there a way to do this at all?
If not, what are my alternatives?
I had the exact same issue and found a solution.
Here's what my XAML looked like this:
<Activity ... xmlns:mylib="clr-namespace:MyProject.ActivityLibrary">
<mylib:MyCustomActivity ... />
</Activity>
The trick that worked for me was to specify the assembly containing my custom activity in the namespace.
Changing the namespace to this made it work:
xmlns:mylib="clr-namespace:MyProject.ActivityLibrary;assembly=MyProject.ActivityLibrary"

Eclipse plugin RCP question

I am creating new Eclipse RCP application. I used "Hello RCP" as template project to create a new project. It works fine. Then I tried adding new menu. I used two extension points "org.eclipse.ui.commands" and "org.eclipse.ui.menu". I created handler class and also defined the menucontribution location uri(). But my menu is not showing up. I strongly suspect my location uri is wrong. But I dont know how to correct it. I have pasted my plugin.xml contents here. Let me know if anyone has a solution. I am following the steps given here http://zenit.senecac.on.ca/wiki/index.php/Add_Menu_to_RCP_Application
You can use ApplicationActionbarAdvisor class to define menus and commands for toolbar as well as menubar.
Firstly you have to declare the commands you want to add in your app like below:
private IWorkbenchAction newAction
Then with the help of ActionFactory class, you have to define the commands in makeActions() method like below:
newAction = ActionFactory.NEW_WIZARD_DROP_DOWN.create(window);
register(newAction);
newAction.setText("New");
Now, after declaration you have to add the commands in menus by using fillMenuBar(IMenuManager menuBar) method :
MenuManager filemenu = new MenuManager("&File", "file");
filemenu.add(newAction);
and if you want to add this command in toolbar, then you have to use following method:
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle());
coolBar.add(toolbar);
toolbar.add(newAction);
Sometimes, you have to use IContributionIem class for declaring commands because all the commands are not in IWorkbenchAction class.
Note: If you are using iContributionItem class then declaration and defination code will be replaced as follws:
IContributionItem show_view;
show_view = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
and rest will be same.

How to provide a custom component in the existing Web page Editor Palette

I want to add a new custom component in the Web page Editor Palete named "myHTMLComponent".
So, as soon as user opens any html page with WPE, myHTMLComponentM should be present there.
How can I do the needful, moreover this component will as well need to generate the code changes accordingly. How to achieve the desired result.
Is there any input I can get for this.
I already created standardmetadata tag, but what next!
Finally, I found the solution of the problem.
For adding new categories in the palette, we need to use pagedesignerextension in plugin.xml as following -
<extension
point="org.eclipse.jst.pagedesigner.pageDesignerExtension">
<paletteFactory
class="com.comp.myeditor.palette.CustomEditorPaletteFactory">
</paletteFactory>
</extension>
Where CustomEditorPaletteFactory will be extending AbstractPaletteFactory. Here in createPaletteRoot(), we can add our category.
public PaletteRoot createPaletteRoot(IEditorInput editorInput){
PaletteRoot paletteRoot = new PaletteRoot();
paletteRoot.add(createStandardComponents());
return paletteRoot;
//return null;
}
private static PaletteContainer createStandardComponents() {
PaletteDrawer componentsDrawer = new PaletteDrawer("CustomHTMLComponent");
TagToolPaletteEntry paletteEntry = new TagToolPaletteEntry(
new FormPaletteComponent(".....);
componentsDrawer.add(paletteEntry);
return componentsDrawer;
}
This will create the component category in the palette and we can add as many components as needed using the componentsdrawer.
For adding a new category in the existing one -
Add this in the constructor -
super();
this._paletteContext = PaletteItemManager.createPaletteContext(file);
this._manager = PaletteItemManager.getInstance(_paletteContext);
Then use Palette Grouping like this -
PaletteGroup controls = new PaletteGroup("CUST HTML");
super.add(controls);
ToolEntry tool = new SelectionToolEntry("CUST Cursor",
"Cursor DESCRIPTION");
controls.add(tool);
setDefaultEntry(tool);
//Custom Marquee
controls.add(new MarqueeToolEntry("Marquee", "Marquee Desc"));
controls.add(new PaletteSeparator());
//This class maintins or load all categories features
controls.add(new CustomComponentToolEntry("Custom Component", "Custom Component Descrition",
This really is a good start but I can't find any tutorial or book that get deeper in this matter. For instance, I don't want to replace the default palette but this code does with "new PaletteRoot()" and I lost my HTML tags. Also I want that my new custom components behave as HTML Tags using Drag and Drop, but I don't know how?????????
More Info:
I discovered this code, that was very helpful, whereas file come from ((FileEditorInput)editorInput).getFile()
PaletteRoot paletteRoot = DesignerPaletteRootFactory.createPaletteRoot(file);
This is very interesting topic and I think we are pioneer documenting this feature of eclipse. Here other good point, I want to personalize the tag... e.g. something similiar what I want to achieve is add a tag like "MY TRUEFALSE TAG" and then when is selected and place it in the HTML Designer, I want to become something like <select><option>YES</option><option>NO</option></select> and I guess that I can achieve it by doing something with the tagTransformOperation extension... if you know how to implement it, please let me know. also there is others extensions(tagConverterFactory, elValueResolver). I am guessing here! please I would like your help.
<extension point="org.eclipse.jst.pagedesigner.pageDesignerExtension">
<paletteFactory ...>
<tagTransformOperation id="plugin.tagTransformOperation1XXXXXX">...
SOLUTION?? (Chinese) -solved with tagConverterFactory
http://www.blogjava.net/reloadcn/archive/2007/11/08/webeditor1.html