I have some issue with calling activity from FREFunction. I had many errors which I could fix but now my app crashes without any erorrs.
Here is my native code:
package com.abhai.myapplication;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREExtension;
public class NotificationExtension implements FREExtension {
@Override
public FREContext createContext(String arg0) {
return new NotificationExtensionContext();
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void initialize() {
// TODO Auto-generated method stub
}
}
package com.abhai.myapplication;
import java.util.HashMap;
import java.util.Map;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
class NotificationExtensionContext extends FREContext {
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public Map<String, FREFunction> getFunctions() {
Map<String, FREFunction> map = new HashMap<String, FREFunction>();
map.put("showToast", new ShowToastFunction());
return map;
}
}
package com.abhai.myapplication;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
class ShowToastFunction implements FREFunction {
@Override
public FREObject call(FREContext freContext, FREObject[] args) {
try {
Context context = freContext.getActivity();
int layoutID = freContext.getResourceId("layout.myactivity");
Intent intent = new Intent(context, MyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("layoutID", layoutID);
context.startActivity(intent);
} catch (Exception e) {
Toast.makeText(freContext.getActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
return null;
}
}
package com.abhai.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
int layoutID = getIntent().getIntExtra("layoutID", -1);
setContentView(layoutID);
Toast.makeText(this, "Success", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}
}
Here is my manifest:
<extensions>
<extensionID>com.abhai.Notification</extensionID>
</extensions>
<manifestAdditions>
<![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<!--<uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch"/>-->
<application android:enabled="true">
<activity android:name="com.abhai.myapplication.MyActivity"/>
</application>
</manifest>
]]>
</manifestAdditions>
It's my as3 class:
package com.abhai.myapplication
{
import flash.external.ExtensionContext;
public class NotificationExtension {
private static var context:ExtensionContext;
public static function init():void {
if(!context) context = ExtensionContext.createExtensionContext("com.abhai.Notification", null);
}
public static function showToast():void {
if (context) context.call("showToast");
}
}
}
It's my as3 code:
package {
import com.abhai.myapplication.NotificationExtension;
import flash.desktop.NativeApplication;
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.text.StageText;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
public class Main extends Sprite {
private var toastButton:AppButton;
public function Main():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.DEACTIVATE, deactivate);
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
NotificationExtension.init();
toastButton = new AppButton("Show Toast");
addChild(toastButton);
toastButton.x = (stage.stageWidth - toastButton.width) / 2;
toastButton.y = 250;
toastButton.addEventListener(MouseEvent.CLICK, onButtonClick);
}
private function onButtonClick(e:MouseEvent):void {
if (e.currentTarget == toastButton) NotificationExtension.showToast();
}
private function generateTextField(rect:Rectangle, initialText:String):StageText {
var shape:Shape = new Shape();
shape.graphics.beginFill(0xD2D2D2);
shape.graphics.drawRect(rect.x - 5, rect.y - 5, rect.width + 10, rect.height +10);
shape.graphics.endFill();
addChild(shape);
var stageText:StageText = new StageText();
stageText.fontSize = 25;
stageText.stage = stage;
stageText.editable = true;
stageText.viewPort = rect;
stageText.text = initialText;
return stageText;
}
private function deactivate(e:Event):void {
NativeApplication.nativeApplication.exit();
}
}
}
package {
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class AppButton extends Sprite {
private var shape:Shape;
private var text:String;
public function AppButton(text:String) {
this.text = text;
addEventListener(Event.ADDED_TO_STAGE, onAdded);
}
private function onAdded(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAdded);
shape = new Shape();
addChild(shape);
var tf:TextFormat = new TextFormat();
tf.size = 25;
var textField:TextField = new TextField();
textField.mouseEnabled = false;
textField.autoSize = TextFieldAutoSize.LEFT;
textField.defaultTextFormat = tf;
textField.text = text;
textField.x = (280 - textField.width) / 2;
textField.y = 10;
addChild(textField);
drawShape(0x008080);
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
private function onMouseDown(e:MouseEvent):void {
drawShape(0x00E6E6);
}
private function onMouseUp(e:MouseEvent):void {
drawShape(0x008080);
}
private function drawShape(color:uint):void {
shape.graphics.clear();
shape.graphics.beginFill(color);
shape.graphics.drawRect(0, 0, 280, 50);
shape.graphics.endFill();
}
}
}
So when I touch on button Show Toast my main activity from air close and my app crashes.
I guess it's not problem with startActivity() because I have try catch there and my toast doesn't work so startActivity() works and app found MyActivity but can't call onCreate cos I don't have my toast with Success or exception.
Can someone tell me where did I go wrong? ;(
Современные инструменты для криптотрейдинга: как технологии помогают принимать решения
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости